HTTP

Contents

HTTP

HTTP based on TCP/IP, it is a protocol used for transmitting web pages over the internet. It is a stateless protocol, which means it does not remember the previous state of the client.

HTTP Request

HTTP Request is a message sent from the client to the server. It contains the following parts:

  • Request line : GET /index.html HTTP/1.1
  • Request header : Host: www.example.com
  • Request body : username=abc&password=123 (optional)

HTTP Response

HTTP Response is a message sent from the server to the client. It contains the following parts:

  • Status line : HTTP/1.1 200 OK
  • Response header : Content-Type: text/html
  • Response body : <!DOCTYPE html><html><body><h1>Hello, World!</h1></body></html>

HTTP Methods

GET → The GET method is used to retrieve or fetch a representation of a resource specified by the URL, GET requests should not have any side effects on the server, it is only for retrieving data.

POST → The POST method is used to submit data to be processed by the server. It is often used to create a new resource or send data to be stored on the server.

PUT → The PUT method is used to update or replace an existing resource with the request payload. It is idempotent, meaning that sending the same request multiple times should have the same effect as sending it once. If the resource does not exist, it can be created.

DELETE → The DELETE method is used to delete a specified resource. It is used to remove a resource from the server. sending the same request multiple times should have the same effect as sending it once.

PATCH → The PATCH method is used to partially update an existing resource. It is similar to the PUT method but is used when you want to update only specific fields or properties of a resource.

POST, PUT, and PATCH

PUT and PATCH are Idempotent, sending the request multiple times will perform the same effect. Generally, we use Post to create a new resource, use PUT to update/create a resource entirely, use patch to partially update a resource.

HTTP Status Code

1xx → Informational responses

2xx → Success

3xx → Redirection

4xx → Client errors

5xx → Server errors

Contents