HTTP Mechanic — API

Type real HTTP requests to a REST server and see the status code and JSON: 18 levels of HTTP methods, status codes and REST semantics.

What you learn in this game

One slip, one request: a method (the verb), an address (the path), then fields if it needs them. GET asks for what is at that address. GET is a safe method: the client asks for no change at all, so the board stays the same, and sending it again changes nothing either (idempotent). Success is answered 200 OK with the content: a collection address answers a list, one card's address answers one object.

404 Not Found: the server found nothing at that address (or will not admit there is something). A 4xx code means the problem is in the request: its address, its method or its content. Always read the status code first, then the body.

POST asks the address to process the slip's content by its own rules; on the collection /orders that means making a new card. The server gives the number, then answers 201 Created with a Location header pointing at the new resource. POST is not idempotent: two identical slips make two cards.

422 Unprocessable Content: the server understands the content type (JSON) and the content is well formed, but it cannot be acted on, for instance a required field is missing. Tell it apart from 400 Bad Request (the content itself is broken, JSON that cannot be read) and 404 (the address does not exist). The server refuses before storing anything.

PUT asks for the resource at that address to be replaced with the slip's content: the slip is a whole card, and fields not written are no longer there. PUT is idempotent: the same slip sent many times has the same result as sent once. An existing resource replaced successfully is answered 200 OK (or 204).

PATCH (RFC 5789) carries a set of changes, not a whole card: only the fields written change, the rest stay. The format of the changes is named in Content-Type; the common one for JSON is JSON Merge Patch, application/merge-patch+json. PATCH is not guaranteed to be idempotent.