question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exercise Tracker API is not RESTful

See original GitHub issue

The exercise tracker’s API, as described on the GitHub repo, is not RESTful. I’m happy to submit a fix for this myself, but I believe these microservice challenges use some automated tests, so I thought it would be best to track the issue here until we’re in a good spot for breaking changes. If we only need to change the project’s documentation and the example’s endpoints then this will be easy.

https://github.com/freeCodeCamp/boilerplate-project-exercisetracker/

Current API

POST /api/exercise/new-user - “new-user” isn’t a resource. Better to stick with “users” as the resource and let the HTTP define new-ness. GET /api/exercise/users POST /api/exercise/add - RESTful APIs should avoid using verbs in the path GET /api/exercise/log - This is awkward as “log” is also a verb. Also, we’re really getting a log from the user resource, so why not make that clear in the URL?

All of the endpoints exist under /api/exercise, which implies a strange hierarchy of users and user logs being properties of an exercise, which is not right.

Proposal

GET /api/users - Returns all users POST /api/users - Creates a new user GET /api/users/{user_id}/logs?[from][to][limit] - Returns all exercises entered for the specified user POST /api/users/{user_id}/exercises - Logs a new exercise to the specified user

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
ProfessorSaltycommented, Mar 13, 2021

I believe this was done so that someone could have all these APIs running on a single domain without potential conflicts.

That’s a point I hadn’t considered. IMHO, it would make more sense to scope the /api endpoints to each project rather than the other way around, eg. exercise/api/..., timestamp/api/.... This would be clearer in intent and even allow students to serve clients in the base URL (excerise/public, for example) or pull the API code into a separate application easily.

is this opinion based or best practice (i.e. referenced somewhere that RESTful should not use verbs)?

I wish I had some text to point to as gospel. Really, this is my opinion based on my understanding of RESTful architecture. I’m certainly fallible - I would even say error prone - but I’m confident in my case here even if I can’t point to why.

2reactions
RandellDawsoncommented, Mar 12, 2021

I like the idea of /api/timestamp/[date] because as was mentioned by @scissorsneedfoodtoo, a single domain could house multiple APIs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

REST API Project: Exercise Tracker | by Libor Marko
It is a set of rules that developers follow when they create their API. I created this simple REST API Exercise Tracker project,...
Read more >
Exercise Tracker - freeCodeCamp APIs and Microservices ...
This is a full walkthrough for the Exercise Tracker project on freeCodeCamp. We connect to a MongoDB database and set up some models...
Read more >
Exercise Tracker PART 1 - APIs and Microservices - YouTube
In this APIs and microservices project, we do part one of building an exercise tracker API. This is the fourth part of four...
Read more >
Top 10 Fitness APIs For 2021
The Google Fit REST APITrack this API allows users to collect, store and reference fitness data in order to create third-party fitness ......
Read more >
REST API in JavaScript on Exercism
Implement a RESTful API for tracking IOUs. ... an instance of this database as an argument (and set up a default value for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found