DEV Community

Maximo Martinez Soria
Maximo Martinez Soria

Posted on • Updated on

HTTP Explained

HTTP stands for Hyper Text Transfer Protocol and is the one that specifies the rules on the communication between two computers through internet.

Verbs

The verbs are actions that define what each request is about to do.

  • 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 lots of endpoints for a resource or we can just use the main word and use the verbs.

For example:

  • GET /books
  • POST /books
  • DELETE /books

Is better than:

  • GET /get-all-books
  • POST /create-a-book
  • DELETE /delete-book

Status

Every request is going to return a status code. Let's see which codes exist and why.

  • 1xx: pending. Nothing happened yet.
  • 2xx: success.
  • 3xx: usually a redirect.
  • 4xx: client-side errors.
  • 5xx: server-side errors.

Common Status Codes

  • 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.

Latest comments (0)