API Documentation - Kriaa89/VivaFit GitHub Wiki
API Documentation
Welcome to the API Documentation for VivaFit. This page provides details on the RESTful endpoints available across our application. All endpoints follow a consistent response format and are secured using JWT and Firebase authentication.
🔐 Authentication
POST /api/users/register
- Description: Create a new user account.
- Request Body:
{ "firstName": "John", "lastName": "Doe", "email": "[email protected]", "password": "yourpassword" }
- Response: Status 201 with created user details.
POST /api/users/login
- Description: Authenticate an existing user.
- Request Body:
{ "email": "[email protected]", "password": "yourpassword" }
- Response: Status 200 with JWT token and user profile data.
👤 User Management
GET /api/users/profile
- Description: Retrieve the authenticated user's profile.
- Headers:
- Authorization: Bearer token
- Response: Status 200 with user details (excluding sensitive info).
PUT /api/users/profile
- Description: Update the authenticated user's profile.
- Headers:
- Authorization: Bearer token
- Request Body:
{ "firstName": "John", "lastName": "Doe", "age": 30, "weight": 80 }
- Response: Status 200 with updated user details.
🏋️♂️ Exercise Endpoints
GET /api/exercises
- Description: Fetch a list of exercises.
- Query Parameters:
page
for pagination,limit
for records per page,filter
options (e.g., muscle group, equipment).
- Response: Status 200 with paginated exercise data.
GET /api/exercises/:id
- Description: Fetch a single exercise by its ID.
- Response: Status 200 with exercise details.
💪 Workout Program Endpoints
POST /api/programs
- Description: Create a new workout program.
- Headers:
- Authorization: Bearer token
- Request Body:
{ "programName": "Strength Builder", "workouts": [ { "dayOfWeek": "Monday", "exercises": [ { "exerciseId": "ex123", "sets": 3, "reps": 12, "restTime": 60 } ] } ] }
- Response: Status 201 with created program details.
GET /api/programs
- Description: Retrieve all workout programs for the authenticated user.
- Headers:
- Authorization: Bearer token
- Response: Status 200 with a list of programs.
PUT /api/programs/:id
- Description: Update a specific workout program.
- Headers:
- Authorization: Bearer token
- Request Body: Contains fields to update.
- Response: Status 200 with updated program details.
DELETE /api/programs/:id
- Description: Delete a workout program.
- Headers:
- Authorization: Bearer token
- Response: Status 200 with a success message.
🔍 Error Handling
All API endpoints follow a standard response format:
- Success Response:
{ "success": true, "data": { ... }, "message": "Optional success message" }
- Error Response:
{ "success": false, "message": "Error description" }
⚙️ Workflow Diagram
Below is a high-level workflow diagram illustrating the flow of API calls in VivaFit:
flowchart TD
A[User Sign-Up/Login] --> B[Receive JWT Token]
B --> C[Access Protected Routes]
C --> D[GET /api/users/profile]
C --> E[GET /api/exercises]
C --> F[POST /api/programs]
F --> G[Workout Program Management]
🔗 Useful Links
- Project Documentation:
- Fetching Data & API Tools:
- Axios Documentation - Learn how to fetch data with Axios.
- Fetch API Documentation on MDN - Native browser API for fetching data.
- Additional Resources:
- HTTP Status Codes - Reference for HTTP status codes.
- Mermaid.js Documentation - Guide for creating diagrams.