An overview of http
Published: 2023-02-24 02:33:02

## The page document

click the link [godaddy website](https://hk.godaddy.com/en/whois
), open the devloper Tool by press CTR+F12.

![resources it requested](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9lm50d8w2jb6e3j3kcrs.png)


![resources it requested](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jig72zwa54dtx0gr0739.png)

Refresh this page. you will see all the resources the exploer has requested. The page you are seeing is a html document , which is reconstructed from different resources, such as layout(the .css file),images ,js, videos and some other format resources.



## request and response.


![request and response brief](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o9relii2zgu01aaikwp0.png)

1. It's the program(client) on behalf of a user to initiate a request, such as web browers and other tools programmers used like curl. The client initiate the TCP connection, after network connection was estabilished,it send the request.

2. Server serve the document as reqeusted. it appears as only a single machine ,but it may actually be a collection of machines. 

> share the load, other software instances like cache,db servers.

3. proxies between client and server.

![http request header](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ajdu9urw79e5ldoydp7r.png)


![request uri](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ktc00x143lkmznqdtan0.jpg)



http request and response massage format

```
       Full-Request   = Request-Line              ; 
                        *( General-Header         ; 
                         | Request-Header         ; 
                         | Entity-Header )        ; 
                        CRLF
                        [ Entity-Body ]           ; 
```

`Request-Line   = Method SP Request-URI SP HTTP-Version CRLF`



A exmaple of request message 

![request message](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gx1vatmkq84gthtd0c5r.jpg)



```
       Full-Response  = Status-Line               
                        *( General-Header         
                         | Response-Header        
                         | Entity-Header )        
                        CRLF
                        [ Entity-Body ]           
```
`Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
`
A exmaple of response message 

![response message](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tstevsq2ojgs4e4h0vaz.jpg)


> user-agent

## http method

- GET   
  should only retrieve data
- POST  
 submit a form to the server, cause a change or effect to the 
 resource.
- PUT   
  create a resource
- DELETE 
  delete a resource 
- HEAD  
  identical to GET except the server does not return message 
  body in the response.
- OPTIONS 
  check the methods of the resource supported, work together 
  with http header **Allow**

- PATCH

## status code
Informational responses (100 – 199)
Successful responses (200 – 299)
Redirection messages (300 – 399)
Client error responses (400 – 499)
Server error responses (500 – 599)

The frequently used status codes

- 200 OK
   the server handled the request successfuly.
- 301 moved Permanently
    the resource was moved. work with the response header 
    **location**
- 307 Temporary Redirect
    work with the response header **location**

> classic usage:short url <
> classic usage:short url
- 308 Permanent Redirect
    work with the response header **location**
- 400 Bad Request
- 401 Unauthorized
    no valid sign
- 404 not found
    no resource specified in the request
- 405 method not allowed
    the resource does not support the request method
- 500 Internal Server Error
    the remaining server side error can't fall to other categroy.
502 bad gateway
    gateway error or gateway receives invalid response from the origion server.
503 Service Unavailable 
    the server is down for maintance or overloaded. Might return **retry-after** in response header.
504 gateway timeout
   gateway doesnt get the response from origion server in limited time or even not able to connect the origion server.


## HTTP Headers

- accept
- content-type
- content-length


connection-alive


stateless