A Cheatsheet of HTTP-Related Questions
What is HTTP?
- HTTP stands for Hyper Text Transfer Protocol, used for transferring data over a network
- HTTP is the foundation of data communication between web clients (often browsers) and servers (often computers in the cloud) for the World Wide Web.
- Communication between client computers and web servers is done by sending HTTP Requests and receiving HTTP Responses
- HTTP is stateless, every request is completed independently
What is HTTPS?
- HTTPS stands for Hyper Text Transfer Protocol Secure, data sent is encrypted through SSL/TLS
- Install SSL certificate on the web host, SSL (secure socket layer), TLS (Transport Layer Security)
- GET: requests data from a specified resource
- POST: send data to the server to create/update a resource — always contains HTTP request body to send to the data (more secure)
- PUT: means “insert, replace if already exists”, similar to POST, but the same PUT request multiple times will always produce the same result
- HEAD: is almost identical to GET but without the response body.
- PATCH: is making partial changes to an existing resource.
- DELETE: deletes the specified resource.
HTTP Response Status Codes
- Informational responses (100–199)
- Successful responses (200–299)
- Redirection messages (300–399)
- Client error responses (400–499)
- Server error responses (500–599)
Requests & Responses
- HTTP requests are generated by a user’s browser as the user interacts with web properties (clicks on a hyperlink, the browser will send a series of “HTTP GET” requests)
- HTTP requests all go to either an origin server or a proxy caching server, and that server will generate an HTTP response.
- HTTP responses are answers to HTTP requests.
- Requests: method, path, version of the HTTP protocol, headers(content)
- Responses: version of the HTTP protocol, status code, status message, headers(content)
- headers as key: value involving -> method, path, protocol
- general: request URL, the request method, status code, remote address, referrer policy
- request: host, language, cookies, accept-xxx, content-type, content-length, authorization, user-agent, referrer
- response: date, server, set-cookie, content-type, content-length
- content-type in the headers — what kind of data you are sending/receiving based on this request
- the content-type describes form data that is sent in a single block in the HTTP message body (in the headers)
What Happens When You Enter Google.com on The Browser
Browser — Internet — Server — Internet — Browser
Once you enter Google.com, the browser extracts the domain name from the URL and sends a request via HTTP protocol (like an agreement based on TCP/IP) which connects to TCP/IP first before reaching to server.
- The browser first checks the cache for a DNS record to find the corresponding IP address of google.com.
- If the URL does not exist DNS cache, the browser looks up the IP using recursive DNS lookup. (DNS resolver — recursive lookup — DNS server)
- If the requested URL does not exist, the DNS request fails and returns nothing.
- If the requested URL exists, the browser initiates a TCP connection with the Web Server.
- The browser sends an HTTP(s) request to the Web Server.
- The server handles the request and sends back an HTTP response.
- The browser renders HTTP content (for HTML content responses, which is the most common).
Good article to read: An overview of HTTP