DEV Community

Discussion on: Best practice for building a RESTful API

jbristow profile image
Jon Bristow

I Disagree with:

  • plural vs singular - There's a lot of nuance here. Most people I've worked with prefer that thing/{id} returns a single thing, while things/ returns all things. As most things go, consistency is more important than what you ultimately choose here.|
  • verbs - Some apis (like AWS) are only verbs. Again, the important part is consistency. Choose one and don't mix unless it's important.

I Agree

  • Return good error statuses (be mindful with 401/403 and 5xx, they sometimes leak information)
  • Frameworks: Pick one and just go. However, be aware that you will eventually hate whichever one you picked.
energeticpixels profile image
Anthony Jackman

Especially the last sentence of the last bullet.

belkheir profile image
Mahamed Belkheir

I like to think about plural vs singular by what that part of the url means, if it's an entity, a plural makes sense, you're not saying "I want all the posts", it's more like "I want to interact with the entity 'Posts'", with a GET at "/" being all/pagination, "/:id" being a singular fetch, Posting to a entity would be making a create request and what not.

I like this approach because it lowers variance, and imo easier to abstract for the frontend, instead of having to manually pick the singular/plural form, you can have just one word to refer to all the entity CRUD operations