My Fitness Tracker API is a RESTful API designed to help users track their fitness routines and workout progress. The API is built with FastAPI and provides a variety of endpoints to manage user authentication and workout routines.
- User authentication with JWT tokens.
- CRUD operations for workout routines.
- Secure endpoints with built-in Swagger UI for easy testing.
- JWT
Authorizebutton in Swagger UI for seamless integration without relying on external tools.
- Version: 1.0
- Specification: OAS 3.1
- OpenAPI JSON:
/openapi.json
- The API is hosted locally or on a server, with all endpoints relative to the base URL.
Returns a welcome message after successful authentication.
Allows new users to register by providing a username, email, and password.
Authenticates the user and returns JWT access and refresh tokens.
Generates a new access token using a valid refresh token.
Returns a welcome message for the fitness tracker.
Creates a new workout routine for the authenticated user.
Retrieves all workout routines for the authenticated user.
Fetches details of a specific workout routine by its ID.
Updates the details of a specific workout routine.
Filters workout routines for the authenticated user by a specific date.
Partially updates workout details for a specific routine.
Deletes a specific workout routine for the authenticated user.
The API integrates a JWT Authorize button directly into the Swagger UI. This feature enhances the user experience by:
- Allowing users to input their Bearer tokens directly in the Swagger interface.
- Automatically including the token in requests to secured endpoints.
- Eliminating the need for external tools like Postman for testing.
- Click the
Authorizebutton in the Swagger UI. - Enter your Bearer token in the format:
Bearer <JWT>. - Test secured endpoints directly in the Swagger interface.
Here is a simple example of how you can use the API:
curl -X POST "http://<base_url>/auth/signup" \
-H "Content-Type: application/json" \
-d '{
"username": "john_doe",
"email": "john@example.com",
"hashed_password": "password123"
}'curl -X POST "http://<base_url>/auth/login" \
-H "Content-Type: application/json" \
-d '{
"username": "john_doe",
"hashed_password": "password123"
}'Response:
{
"access": "<JWT_ACCESS_TOKEN>",
"refresh": "<JWT_REFRESH_TOKEN>"
}curl -X POST "http://<base_url>/workout_routines/createworkout" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <JWT_ACCESS_TOKEN>" \
-d '{
"date": "2024-01-01",
"routine_details": "Chest and Back Workout"
}'curl -X GET "http://<base_url>/workout_routines/showallworkouts" \
-H "Authorization: Bearer <JWT_ACCESS_TOKEN>"- Python 3.9 or higher
- FastAPI
- A database (e.g., SQLite, PostgreSQL)
-
Clone the repository:
git clone https://github.com/<your_github_username>/fitness-tracker-api.git cd fitness-tracker-api
-
Install dependencies:
pip install -r requirements.txt
-
Start PostgreSQL with Docker Compose:
docker-compose up -d
docker-compose.yml:version: "3.8" services: db: image: postgres:latest container_name: my_postgres_container environment: POSTGRES_USER: your_username POSTGRES_PASSWORD: your_password POSTGRES_DB: your_dbname ports: - "5432:5432" volumes: - ./data:/var/lib/postgresql/data
-
Run the application:
uvicorn main:app --reload
-
Access the API documentation:
- Swagger UI:
http://127.0.0.1:8000/docs - ReDoc:
http://127.0.0.1:8000/redoc
- Swagger UI:
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.