An architectural style for designing distributed systems.
A different mindset, the client isn’t doing stuff on the server, the client requests the server to do stuff at the end of whatever else the server thinks needs to be done for this stuff. This gives the server the flexibility to fool around and do things at its own pace.
Internet is the most scaled system on the planet. We took several years to learn from it.
REST is not a standard, but a set of guidelines. Up to some extent any software system is RESTful.
REST is not tied to HTTP but it is often used with it.
Verbs: Get, Post, Put, Delete, Patch, Options, Head. Most frequently used are Get, Post, Put and Delete.
Get:
Get is used to get stuff.
Must be safe and idempotent(go figure).
What if there is a lot of stuff to get?
1. get only if it changed since last got. If-Modified-Since.
2. get a range
Use pagination, sorting and filtering to navigate big lists.
Post:
Post is used to post(send) stuff.
Create or modify
Put:
Put is used to put(send) stuff.
Create or modify.
The payload can be full resource or partial, there is no fixed rule. Make a contract with the server, and get it signed in front of the notary.
HTTP headers:
If-Modified-Since: Wed, 21 Oct 2015 07:28:00 GMT
If-Unmodified-Since:
If-Match:
If-None-Match:
What’s the difference?
When put is used for create, the client can send an id. When post is used for create, the server usually creates an Id.
Delete:
Delete is to request to delete stuff.
The resource doesn’t have to be removed immediately. Removal may be a long running task. In that case give back the URI of the task so that the client can check back later. Return code 202, accepted.
Success return codes:
200 OK
201 Created
202 Accepted (I got it, I will do it soon)
Error return codes:
400 Bad request
401 Unauthorized – Who the heck are you?
403 Forbidden – I know who you are, but you aren’t allowed
404 Not found
406 Not acceptable
409 Conflict
MediaType used for different types of resources.
HATEAOS: Hypermedia As The Engine Of Application State, love this word.