Building a REST service
Designing a REST service: resources and URIs, the meaning of each HTTP method, response codes, statelessness, safe and idempotent methods.
- 29 cards
- 5 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- Scenarios
- Understand
A few cards from the deck
Resource (REST): what is it?
Show the answer
A thing the service exposes and that a URI identifies: a customer, an order, the list of a customer's orders.
The URI names the thing (
/clients/7/orders/42), the HTTP method says the action. A verb in the URI (/deleteClient) mixes the two.Which request creates an order for customer 7 in a well-designed REST service?
POST /clients/7/commandesGET /clients/7/commandes/nouvellePUT /clients/7/creerCommandePOST /clients/7/commandes/creer
Show the answer
POST /clients/7/commandesThe URI points to the collection (a plural noun) and
POSTsays “add an item to it”. A verb in the URI (creer,creerCommande) or aGETthat writes breaks the convention.In a REST service, … reads a resource, … creates one, … replaces it entirely and … removes it.
Show the answer
In a REST service, GET reads a resource, POST creates one, PUT replaces it entirely and DELETE removes it.
PATCHcompletes the list: it changes only the fields sent, wherePUTreplaces the whole resource.Stateless service: what is it?
Show the answer
A service where each request carries everything needed to process it: the server keeps nothing about the client from one request to the next.
Any server can answer any request, which allows load to be spread. The authentication token therefore travels with every request.
A crawler walks the site and a customer vanishes from the database: a route
GET /deleteClient?id=3exists. Which fix follows the REST convention?- Replace it with
POST /clients/3with the word delete in the body - Replace it with
DELETE /clients/3 - Require the crawler to add the
Accept: application/jsonheader - Forbid the route to crawlers in the
robots.txtfile
Show the answer
Replace it with
DELETE /clients/3Crawlers, caches and browsers follow
GETfreely because it is safe.robots.txtwould only keep out polite crawlers, not a browser prefetching a link. A deletion must go through a method that does not fire by itself:DELETE.- Replace it with