Rest APIs Flashcards
What does REST stand for ?
Representation State Transfer
Define your ressource in 4 steps
- Decide what resource(s) need to be available
- Assign URLs to the resources
- Decide what actions the client should be allowed to perform on those resources
- Figure out what pieces of data are required for each action and what format they should be in.
Name 3 best practicies for REST
- Use nouns not verbs
- Get and query should not alter the state
- Use plurals nouns
- Use sub-ressources for relations
- Provide Filter, Sort, Paging for all ressources
- Version your API
- Handle errors with HTTP status messages (200 = ok, 304 not modified
400 error
How does a filter look like ?
GET /cars?color=red Returns a list of red cars
How does a sort look like ?
GET /cars?sort=-manufactorer,+model
What is the basic authentication ?
- URL
- Method
- Header
- Payload
How does a version look like ?
/blog/api/v1
Handle errors with HTTP status messages
200 – OK – Eyerything is working
201 – OK – New resource has been created
204 – OK – The resource was successfully deleted
304 – Not Modified – The client can use cached data
400 – Bad Request – The request was invalid or cannot be served. The exact error should be explained in the error payload. E.g. „The JSON is not valid“
401 – Unauthorized – The request requires an user authentication
403 – Forbidden – The server understood the request, but is refusing it or the access is not allowed.
404 – Not found – There is no resource behind the URI.
422 – Unprocessable Entity – Should be used if the server cannot process the
What headers do you have ?
Get (read)
Post (Create)
PUT (update)
Delete