Introduction to Exercise Logger
Exercise Logger is a comprehensive and easy-to-use API for logging various types of physical activities. Whether you are building a fitness app or a workout tracking system, Exercise Logger provides all the tools you need to accurately track exercises and manage user’s fitness data.
API Endpoints
1. Create a New Exercise
POST /api/exercises
{
"name": "Running",
"duration": 30, // duration in minutes
"calories_burned": 300
}
2. Retrieve All Exercises
GET /api/exercises
Response:
[
{
"id": 1,
"name": "Running",
"duration": 30,
"calories_burned": 300
},
{
"id": 2,
"name": "Swimming",
"duration": 45,
"calories_burned": 400
}
]
3. Update an Exercise
PUT /api/exercises/{id}
{
"name": "Jogging",
"duration": 35,
"calories_burned": 280
}
4. Delete an Exercise
DELETE /api/exercises/{id}
5. Log Workout Session
POST /api/workouts
{
"user_id": 123,
"exercise_id": 1,
"duration": 30,
"calories_burned": 300,
"date": "2023-10-01"
}
6. Retrieve Workout Sessions
GET /api/workouts
Response:
[
{
"id": 1,
"user_id": 123,
"exercise_id": 1,
"duration": 30,
"calories_burned": 300,
"date": "2023-10-01"
},
{
"id": 2,
"user_id": 124,
"exercise_id": 2,
"duration": 45,
"calories_burned": 400,
"date": "2023-10-02"
}
]
7. Create a User
POST /api/users
{
"name": "John Doe",
"email": "johndoe@example.com",
"password": "securepassword"
}
8. Retrieve User Information
GET /api/users/{id}
Response:
{
"id": 123,
"name": "John Doe",
"email": "johndoe@example.com"
}
Example App Using Exercise Logger API
Below is an example of a small app that utilizes Exercise Logger API to create a workout log.
const axios = require('axios');
// Create a new user
axios.post('/api/users', {
name: 'John Doe',
email: 'johndoe@example.com',
password: 'securepassword'
}).then(response => {
console.log('User created:', response.data);
const userId = response.data.id;
// Create a new exercise
axios.post('/api/exercises', {
name: 'Running',
duration: 30,
calories_burned: 300
}).then(response => {
console.log('Exercise created:', response.data);
const exerciseId = response.data.id;
// Log workout session
axios.post('/api/workouts', {
user_id: userId,
exercise_id: exerciseId,
duration: 30,
calories_burned: 300,
date: '2023-10-01'
}).then(response => {
console.log('Workout logged:', response.data);
}).catch(error => {
console.error('Error logging workout:', error);
});
}).catch(error => {
console.error('Error creating exercise:', error);
});
}).catch(error => {
console.error('Error creating user:', error);
});
With the Exercise Logger API, you can streamline the process of tracking exercises and managing user fitness data, making it easy to build powerful fitness applications.
Hash: b11792bf698c0cfbb147b0f75d09091d8c1cb51dff041ce1473367481d483f37