HTTP stands for Hyper Text Transfer Protocol and is the one that specifies the rules on the communication between two computers through internet.
The verbs are actions that define what are we about to do in each request.
- GET: fetch data.
- HEAD: get headers. It's like a GET request but without content.
- POST: create information.
- PUT / PATCH: update information.
- DELETE: delete information.
Verbs, allow us to have different responses for only one endpoint.
We could create lot's of endpoints for a resource or we can just use the main word and use the verbs.
It's better than:
Every request it's going to return a code status. Let's see which codes exists and why.
- 1xx: pending. Anything happens yet.
- 2xx: success.
- 3xx: usually a redirect.
- 4xx: client-side errors.
- 5xx: server-side errors.
- 200: everything is ok. Usually used in GET request.
- 201: everything is ok. Usually used in POST / PUT request.
- 204: usually used to say that a DELETE request was completed successfully. The resource was deleted.
- 400: bad request. Something is wrong in the request.
- 401: unauthorised. You need to specify credentials first.
- 403: forbidden. You don't have permissions over that resource even though you are authenticated.
- 404: not found. Resource doesn't exist.
- 500: internal server error. The request couldn't be processed.
Is there another code status that you frequently use? Comment down below 😊