Türchen 12: HTTP for Magento-Developer

The Hypertext Transfer Protocol (HTTP) is an application-level protocol for distributed, collaborative, hypermedia information systems.

Hypertext Transfer Protocol -- HTTP/1.1 IETF. RFC 2616

Why this blog post?

I gave a talk on Meet Magento Poland. It felt like the worst talk I gave for a long time. I stand on the stage and I didn't know what I want to transport to my audience. My knowledge about HTTP is not bad, but it felt so boring and I had problems to find the gems which are important AND interessting.

I thought a lot about this the last weeks, but I didn't find a solution. I think it is the lack of cool HTTP stories I know. Without anecdotes and motivation why someone should know something telling a story is quite hard. But still, this knowledge is important, so I hope you read on.


The first idea about HTTP goes back to the 30's. Vannevar Bush's had the vision of the microfilm-based information retrieval and management memex. He wrote an article about this 15 years later: As We May Think (1945)

Ted Nelson in 1965 in the Xanadu Project

The first version: came 1991 HTTP 0.9. And since then we had a lot of improvements. The current version is HTTP 1.1 and the RFC for 2.0 is already in draft 13.


HTTP is ...

  • stateless. This means when you make two requests to an HTTP server (theoretically), it doesn't know that is from the same client. In reality this isn't often the case for a bunch of reasons. Nonetheless, states are implemented through additions to HTTP
  • plaintext (readable). If you are looking into the HTTP request, you can read what happens at the moment. This has a lot of upsides, because debugging is a lot easier this way. But debugging is not the main interest for most of the people using HTTP (especially business) and therefore this will change with the next version 2.0.
  • request/response pattern. If you want to have something from the server you send a request. You get back a response. Every HTTP communication (up to 1.1) has this schema.


Lets have a look into the request and response. The following is a sample request made up from the wikipedia:
GET /my-cool-path/filename HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20100101 Firefox/21.0
Referer: http://en.wikipedia.org/wiki/Main_Page
Range: bytes=500-999
Cookie: $Version=1; Skin=new;
Connection: keep-alive
If-Modified-Since:Tue, 25 Nov 2014 03:08:54 GMT
The most important part is the first line:
GET /my-cool-path/filename HTTP/1.1
. What method is used `GET`, what file or directory is requested
and what version is used
. Beside of this a lot of other informations are transported: - `Host`: From which domain is the document requested. With 1.0 we had the assumption, that every domain has its own IP address, so you know exactly which document is meant. But quickly it was evident, that this is not practical and with 1.1 `Host` was a required header. - `User-Agent`: What http client is used. - `Referer`: The page the client comes from. - `Range`: What byte range of the document is requested - What encoding is accepted and which language, cookies, caching, etc.


The response has a header too. It transports the information what type the document is, when it was created, etc. The header and the footer is seperated by two line breaks
HTTP/1.1 200 OK
Date: Mon, 23 May 2005 22:38:34 GMT
Server: Apache/ (Unix) (Red-Hat/Linux)
Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
ETag: "3f80f-1b6-3e1cb03b"
Content-Type: text/html; charset=UTF-8
Content-Length: 131
Accept-Ranges: bytes
Connection: close
An Example Page Hello World, this is a very simple HTML document.

Ein Beitrag von Fabian Blechschmidt
Fabian's avatar

Fabian Blechschmidt entwickelt seit 2004 mit PHP. Vier Jahre später hat er sich damit selbstständig gemacht und ist seit 2011 auf Magento fokusiert. Im Oktober 2011 hat er erfolgreich die Prüfung zum Magento Certified Developer absolviert. In seiner Freizeit besucht er gerne Magento Stammtische und hält unter anderem dort Vorträge. Außerdem organisiert er mit an den Magento Hackathons.

Alle Beiträge von Fabian

Commerce Pundit am

very nice post i really enjoy reading it. keep sharing such amzing post here. thanks

Anna Völkl am

Thumbs up, I really like to see some web development fundamentals covered here: Things lots of developers rely on every day. I think it's essential to know what's behind our daily "tools". And the diagrams are nice :)

Nils Preuß am

Nice one Fabian. Too many developers are absolutely clueless about the protocol they use most to deliver their stuff. For developers you maybe missed one interesting Method: OPTIONS to explore the capabilites of servers/resources.

Fabian Schmengler am

Sorry, I meant 418, not 417!

Fabian Schmengler am

Heads up for your initiative to bring more http knowledge to the developer world. To lighten up the "boring" topic, the status code 417 deserves at least a mention, don't you think? Also I'd bring attention to 303 for post-redirect-get (form submission) and, relevant for APIs, the PATCH method

Dein Kommentar