The HTTP-protocol has a couple of methods that you can use to retrieve, send, remove or update information.
OPTIONS
The OPTIONS method returns (among other information) a list of methods allowed by the server. For example, the server can respond that some methods are not allowed on certain routes.
HEAD
The HEAD method is used to return all headers in the same manner as a GET request would, but without sending any data back. This is used to check if certain resources exist on the server.
GET
Probably the most common method, GET is used to retrieve data from a server or API.
request.get('someApiURL', response => { // handle response data } )
POST
Another very common method. POST simply uploads new data to the server/API url.
Example:
request.post('someApiUrl', {
data: {
key: value
}
}
)
PUT
Updates information of an existing entry or upload a new entry if it does not already exist. It behaves
a bit like a POST request, but should not be used in that manner.
PATCH
The PATCH method is used to update a specific piece of information of an existing entry. For example, to update the username if an existing user in a database.
DELETE
Obvious due to it's name, the DELETE method simply deletes information (if no security protocol is there to prohibit it).
Fun exercise! Good tutorial for beginners! π
HTTP Cheatsheet
Methods
The HTTP-protocol has a couple of methods that you can use to retrieve, send, remove or update information.
OPTIONS
The OPTIONS method returns (among other information) a list of methods allowed by the server. For example, the server can respond that some methods are not allowed on certain routes.
HEAD
The HEAD method is used to return all headers in the same manner as a GET request would, but without sending any data back. This is used to check if certain resources exist on the server.
GET
Probably the most common method, GET is used to retrieve data from a server or API.
POST
Another very common method. POST simply uploads new data to the server/API url. Example:
PUT
Updates information of an existing entry or upload a new entry if it does not already exist. It behaves a bit like a POST request, but should not be used in that manner.
PATCH
The PATCH method is used to update a specific piece of information of an existing entry. For example, to update the username if an existing user in a database.
DELETE
Obvious due to it's name, the DELETE method simply deletes information (if no security protocol is there to prohibit it).
Status Messages
Servers return status messages whenever a request is received. There are quite a lot of them, see the full list here. But there are some that are more commonly used than others.
400 - Bad Request
Server did not understand the request.
401 - Unauthorized
Client needs to authenticate itself to get the requested response
403 - Forbidden
Client does not have the proper access rights, even though the client is authenticated and known to the server.
404 - Not Found
Ah, the famous 404. The requested resource cannot be found. Could be due to an invalid URL or that the requested resource simply does not exist.
405 - Method Not Allowed
The used method (GET, POST, PUT, PATCH, DELETE) is not allowed on the server.
418 - I'm a teapot
The server refuses to brew coffee with a teapot.
500 - Internal Server Error
Something went wrong on the server.