About HTTP

HTTP stands for HyperText Transport Protocol.
How It Works

1) A client machine makes a request to a server.

The request is a text document containing a Verb, Headers, and Content.
ex: POST, Content Length: 11, Hello World

2) The server processes the request and may return a response.

The response is a text document containing a Status Code, Headers, and Content.
ex: 201, Content Type: text, Hello World

The server is stateless. It process each request individually.
Request

The HTTP Request document.

Verb

The action to perform on the server.

GET - request a resource
POST - create a resource
PUT - update a resource
PATCH - update parts of a resource (ex: the address of the customer, not the whole customer)
DELETE - delete a resource
etc

Headers

Metadata about the request.
A set of Name/Value pairs.

Content Type - the format of the content
Content Length - size of content
Authorization - who is making the request
Accept - the formats I can accept in the response
Cookies - state data
etc

Content

Could be any data.

HTML, CSS, JavaScript, XML, JSON, etc.

The content format may be limited by the Verb.
For instance, GET requests don't have any Content because they are just requesting information.
Response

The HTTP Response document.

Status Code

The status of the requested operation.

100-199: informational
200-299: success
300-399: redirection
400-499: client errors
500-599: server errors

Headers

Similar to the request headers.

Content Type
Content Length
Expires - when the data is considered stale
Cookies
etc

Content

Similar to the request content.
Curl

curl is a command line tool that makes a simple HTTP Request.

Http Request


curl google.com
Displays the HTML/CSS/etc that is returned by the request.

View Headers


curl google.com -I
Displays just the headers of the response.


curl google.com -i
Displays the headers and the content of the response.