NestJSREST APIs & DTOsLesson 43 / 69

REST conventions

Docs15 min

REST conventions

REST is a set of naming habits that make APIs guessable:

ActionRouteVerb
ListGET /booksread
Read oneGET /books/42read
CreatePOST /bookscreate
ReplacePUT /books/42update
TweakPATCH /books/42update
RemoveDELETE /books/42delete

Nouns in the path, verbs in the method, status codes tell the truth: 201 created, 400 your fault, 401 unauthenticated, 404 not there, 409 conflict. An API that follows the table is half-documented by existing.

Exercise

Design the routes for a favorites feature on this roadmap app. Write the method + path + status code for each of the five actions.