REST API Basics Module #63 Flashcards
Generally speaking, what are the 2 main categories of API’s?
REST and GraphQL.
SOAP is another but not very popular in the JS world.
In REST what is an endpoint?
An endpoint is a place where a client can access data (most often JSON) from a server.
What method signals to the server that we want to read data?
This is the GET Method
Example
GET /people returns a list of people
GET /person/1 returns data for that person
What method signals that we want to provide data to the endpoint?
POST
The endpoint is the same but another action takes place.
What methods can we use to update or even remove data?
PUT or PATCH can update data
DELETE is used to remove a chunk of data
Sometimes however, POST is used for everything that isn’t reading.
What’s considered a best practice when naming endpoints
Use a noun to describe what kind of data is being exchanged.
What does it mean to say, “A REST API is stateless”?
It means that the API retains no memory from one request to another.
What mechanisms are used to monitor useage and force limits?
API Keys identify API consumers as well as login/password methods and session tokens.
What two response forms are provided to the user as a way to understand the status of a request?
Status codes and response bodies. For example:
Status code 200 OK means everything worked fine
A 404 NOT FOUND is obviously an error that occurred. But there are many more:
201 Created: Typically a response to a POST request. The request has been completed, and a new resource has been created.
400 Bad Request Due to a request error that was generated on the client, the server cannot process the request. Errors can include a malformed request, size too large to be handled, or others
401 Unauthorized Sent when authentication is required and the client is not authorized
403 Forbidden The resource is not available for various reasons. If the reason is authentication, prefer the 401 Unauthorized status code.
405 Method Not Allowed The resource is not available through that HTTP method, but might be with another.
500 Internal Server Error A generic server error message, given when an unexpected condition was encountered and no more specific message is suitable.
Full List: https://flaviocopes.com/http-status-codes/
Response codes are one thing but, what exactly is the response body?
Typically it’s the JSON that gets returned or in the case of an error, that is the response body.