Skip to content

Instantly share code, notes, and snippets.

@abernier
Last active January 21, 2019 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save abernier/78727a3ddb418e346cfde1fabc471fe8 to your computer and use it in GitHub Desktop.
Save abernier/78727a3ddb418e346cfde1fabc471fe8 to your computer and use it in GitHub Desktop.

RESTful

Une API se dira "RESTful" quand elle va respecter certaines conventions.

C'est presque comme un label de qualité, que les développeurs vont aimer. Par ex, dans une API permettant de laisser des commentaires, pour CREER un nouveau commentaire, une API RESTful utilisera le verbe POST ainsi qu'un nom de route au pluriel, soit : POST /comments.

Bien sûr, elle aurait pu choisir autre chose, comme une route au singulier, mais par convention elle tâchera de respecter le pluriel. Comme ça, elle fera plaisir aux développeurs utilisant son API, qui s'y retrouveront plus facilement par habitude de toujours retrouver cette convention entre les différentes APIs qu'ils utiliseront.

La liste complète des conventions RESTful sont :

handler Description
GET /comments LIST all comments
POST /comments CREATE a new comment
GET /comments/3 SHOW comment of id #3
PUT /comments/3 UPDATE (entirely) comment of id #3
PATCH /comments/3 UPDATE (partially) comment of id #3
DELETE /comments/3 REMOVE comment of id #3

Plus d'info sur le RESTful: https://www.restapitutorial.com/lessons/httpmethods.html


NB: Restful est aussi un jeu de mot entre REST et la définition de restful en anglais:

Something that is restful helps you to feel calm and relaxed.

🧘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment