core
http is how browsers and servers talk. it moves data back and forth. many protocols exist, http happens to be the most common.
at its core, http follows two simple ideas: it doesn’t remember anything, and the browser always starts the conversation.
statelessness:
- http forgets everything once a request is done. every request must include all the info the server needs. no previous context is assumed.
- since the server isn’t storing who you are or what you did before, the request needs to carry things like auth tokens or cookies when logging in or checking a profile.
- this design keeps servers simpler. they don’t track sessions or store memory about users.
- statelessness also scales better. any request can go to any server. if one fails, nothing breaks.
client-server model:
- the browser (client) asks for something. that could be a webpage, some data, an image, anything.
- the server listens, processes the request, and sends back a response.
- the client always initiates. the server never starts talking on its own.
http packets need a reliable way to travel between client and server. that’s where tcp comes in. tcp ensures the data arrives correctly and in order. udp exists too, but it’s less reliable. http chooses tcp because losing parts of a webpage isn’t an option.