“If you want to build a ship, don’t drum up the men and women to gather wood, divide the work, and give orders. Instead, teach them to yearn for the vast and endless sea.” - Antoine de Saint-Exupery;
HTTP
: Hypertext Transfer Protocol.
HT
: Hypertext - content with references to other content.
Hyperlinks
: Links; references between HT resources.TP
: Transfer Protocol - set of guidelines surrounding the transmission of data.
request/response
protocol.clients
& servers
.
Clients
: User Agent - the data consumer.Servers
: Origin - Data provider & where the application is running.Properties of HTTP
Reliable Connections
: Messages passed between a client & server sacrifice a little speed for the sake of trust.
TCP
is HTTP’s preferred connection type.Stateless Transfer
: HTTP is a stateless protocol - meaning it does not store any kind of information.
Intermediaries
: Servers or devices that pass your request along which come in three types:
Proxies
: Modify your request so it appears to come from a different source.Gateways
: Pretend to be the resource server you requested.Tunnels
: Simply passes your request along.Structure of an HTTP Request
GET / HTTP/1.1
Host: appacademy.io
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Example of how an HTTP request looks like for visiting appacademy.io
Request-line & HTTP verbs
Method
: Indicated by an HTTP Verb.URI
: Uniform Resource Indicator that ID’s our request.HTTP
Version : Version we expect to use.GET
: Used for direct requests.POST
: Used for creating new resources on the server.PUT
: Used to updated a resource on the server.PATCH
: Similar to PUT, but do not require the whole resource to perform the update.DELETE
: Used to destroy resources on the server.Headers
Host
: Root path for our URI.User-Agent
: Displays information about which browser the request originated from.Referer
: Defines the URL you’re coming from.Accept
: Indicates what the client will receive.Content
- : Define Details about the body of the request.URL encoding
: Most common way form data is formatted.name=claire&age=29&iceCream=vanilla
Sending an HTTP request from the command line
nc -v appacademy.io 80
man nc
to open the netcat manual.Structure of a Response
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: close
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Cache-Control: max-age=0, private, must-revalidate
Set-Cookie: _rails-class-site_session=BAh7CEkiD3Nlc3Npb25faWQGOgZFVEkiJTM5NWM5YTVlNTEyZDFmNTNlN; path=/; secure; HttpOnly
X-Request-Id: cf5f30dd-99d0-46d7-86d7-6fe57753b20d
X-Runtime: 0.006894
Strict-Transport-Security: max-age=31536000
Vary: Origin
Via: 1.1 vegur
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 51d641d1ca7d2d45-TXL
<!DOCTYPE html>
<html>
...
...
</html>
Status
status line
)HTTP/1.1 200 OK
HTTP status codes
: numeric way of representing a server’s response.
Status codes 100 - 199: Informational
Status codes 200 - 299: Successful
Status codes 300 - 399: Redirection
Status codes 400 - 499: Client Error
Status codes 500 - 599: Server Error
Headers : Work just like HTTP requests.
Location
: Used by client for redirection responses.Content-Type
: Let’s client know what format the body is in.Expires
: When response is no longer validContent-Disposition
: Let’s client know how to display the response.Set-Cookie
: Sends data back to the client to set on the cookie.Data
: If the request is successful, the body of the response will contain the resource you have requested.