Week 5: API Endpoints
March 7, 2025
Thoughts of the week
This week, I solidified my thoughts on which DB architecture I wanted to use. I will be sticking with MongoDB as I have used it before and am currently using it on a project I am working on. I was advised to do some testing when going through this process such as making sure the compsci server can communicate with MongoDB and have data be sent back successfully. This test was successful and confirmed my go-ahead to continue with MongoDB.API Endpoints Overview
Beacon Endpoints
/api/beacons
Retrieves all beacon devices in the database. This will be used in the admin interface to manage beacon devices.
/api/beacons/:id
Retrieves a specific beacon by ID, including its RSSI threshold settings and location information.
/api/beacons
Creates a new beacon in the system. Requires authentication as this is an admin function.
/api/beacons/:id
Updates an existing beacon's information (name, RSSI threshold, etc.).
/api/beacons/:id
Removes a beacon from the system.
/api/beacons/nearby
The key endpoint for the iOS app - accepts RSSI readings and returns nearby beacons with their associated workout stations. This is what enables the proximity-based workout recommendations.
Station Endpoints
/api/stations
Retrieves all workout stations with their associated beacons and workouts.
/api/stations/:id
Retrieves detailed information about a specific workout station.
/api/stations
Creates a new workout station and links it to a beacon and workout program.
/api/stations/:id
Updates an existing station's details or changes its associated workout.
/api/stations/:id
Removes a station from the system.
/api/stations/beacon/:beaconId
Retrieves all stations associated with a specific beacon, allowing for multiple workout options at the same physical location.
Workout Endpoints
/api/workouts
Retrieves all workout programs in the database.
/api/workouts/:id
Retrieves a specific workout with its exercise list, sets, reps, and other parameters.
/api/workouts
Creates a new workout program with specified exercises.
/api/workouts/:id
Updates an existing workout's parameters or exercise list.
/api/workouts/:id
Removes a workout from the system.
Exercise Endpoints
/api/exercises
Retrieves all exercises in the database.
/api/exercises/:id
Retrieves details about a specific exercise including instructions and recommended sets/reps.
/api/exercises
Adds a new exercise to the library.
/api/exercises/:id
Updates an existing exercise's details or instructions.
/api/exercises/:id
Removes an exercise from the system.
User Endpoints
/api/users
Registers a new user in the system.
/api/users/login
Authenticates a user (In future: returns a JWT token for protected endpoints.)
/api/users/profile
Retrieves the current user's profile information.
/api/users/profile
Updates the current user's profile information.
Workout History Endpoints
/api/history
Retrieves workout history for admin use.
/api/history/:id
Retrieves a specific workout history entry.
/api/history
Creates a new workout history entry when a user completes a workout.
/api/history/user
Retrieves all workout history for the current user.
/api/history/user/stats
Retrieves workout statistics and trends for the current user.
Next Steps
My immediate next steps are to implement these API endpoints and test them thoroughly. I'll start with:
- Setting up the Node.js/Express server infrastructure
- Implementing the MongoDB models for each data entity
- Building and testing the Beacon and Station endpoints first, as these are core to the proximity functionality
- Possibly in future: Implementing user authentication with JWT
- Creating a simple test client to verify the RSSI-based proximity detection
Once these are working reliably, I'll continue with implementing the workout and exercise endpoints, followed by the user workout history tracking. I expect to have the core API functionality working within the next week, which will allow me to focus on integrating it with the iOS app in the final weeks of the project.