This repo contains all the source code to run the micro API for the sports analytics dashboard SportSee.
To start this project, you are free to use Docker or not. In this documentation, we will see several methods to launch the project easily.
- NodeJS (version 12.18) or higher (tested up to Node 20.0)
- Yarn
If you are working with several versions of NodeJS, we recommend you install nvm. This tool will allow you to easily manage your NodeJS versions.
- Fork the repository
- Clone it on your computer.
- The
yarncommand will allow you to install the dependencies. - The
yarn devcommand will allow you to run the micro API.
- The
docker image build --no-cache -t micro-api .command will allow you to build your image. - The
docker container run --name micro-api -p 8000:8000 -dt micro-api yarncommand will allow you to create your Docker container and run your image on port 8000. - The
docker container stop micro-apicommand will allow you to stop your micro-api. - The
docker container rm micro-apicommand will allow you to delete your micro-api container.
Finally, if you have VsCode, you can easily launch your project in a docker environment.
You will need the Remote Development extension. Once you have this extension installed, just click on the Reopen in Container button.
Once in the container, run the yarn dev command.
The API uses JWT (JSON Web Token) authentication. To access the endpoints:
- First obtain a JWT token by logging in:
curl -X POST http://localhost:8000/api/login \
-H "Content-Type: application/json" \
-d '{"username": "sophiemartin", "password": "password123"}'- Use the received token in subsequent requests in the Authorization header:
curl -H "Authorization: Bearer your-jwt-token" http://localhost:8000/api/user-infoCurrently, the API has three demo users:
- username:
sophiemartin, password:password123 - username:
emmaleroy, password:password789 - username:
marcdubois, password:password456
POST /api/login- Authenticates a user and returns a JWT token- Required body:
{ "username": "string", "password": "string" } - Returns:
{ "token": "jwt-token", "userId": "string" }
- Required body:
All these endpoints require authentication via a Bearer token in the header:
Authorization: Bearer <your_token>
GET /api/user-infoReturns the user profile and overall statistics:
{
"profile": {
"firstName": "string",
"lastName": "string",
"createdAt": "string",
"age": number,
"weight": number,
"height": number,
"profilePicture": "string"
},
"statistics": {
"totalDistance": "string",
"totalSessions": number,
"totalDuration": number
}
}GET /api/user-activity?startWeek=<date>&endWeek=<date>Returns an array of running sessions between two dates (sorted ascending, future dates excluded).
Parameters:
startWeek: Start date (ISO format)endWeek: End date (ISO format)
GET /images/<filename>Serves the static profile images (e.g. the profilePicture URLs returned by /api/user-info).
- All dates should be in ISO format (YYYY-MM-DD)
- All distances are in kilometers
- All durations are in minutes
# Login
curl -X POST http://localhost:8000/api/login \
-H "Content-Type: application/json" \
-d '{"username": "sophiemartin", "password": "password123"}'
# Get user data
curl -H "Authorization: Bearer your-jwt-token" http://localhost:8000/api/user-info
# Get user activity
curl -H "Authorization: Bearer your-jwt-token" \
"http://localhost:8000/api/user-activity?startWeek=2025-01-01&endWeek=2025-01-31"The API will return appropriate HTTP status codes:
- 400: Bad Request (missing username/password)
- 401: Unauthorized (missing or invalid token)
- 403: Forbidden (invalid token)
- 404: Resource not found
- 500: Server error