Apiary

Go to Navigation
Back to Articles

Back to the roots. Meet HTTP.

By netmilk (ntmlk, adam@apiary.io) on 22 Jul 2013

There are a lot of people talking about HTTP. Really. For a long time. Academics, visionaries, hipsters. Everybody and everything is talking HTTP. Twitter, Facebook, Web applications in general, browsers, APIs, mobile devices. Even your house, [lamp][hue] and even a car can speak HTTP. It has been said that it is so simple it can be used in even the most simple computer processors. Everyone is talking about it. But oh my, where is it? Can I touch it? When was the last time you actually saw it? It’s so abstract! It’s hidden on the lowest level. It’s incredible how hard it is to get a raw, naked HTTP messages. So where is HTTP and what does it actually look like?

There are ways to find it. You can see what is happening in your browser or in your backend server. But this is not the raw, un-pre-processed ASCII representation of a HTTP message you are looking for. If you are not a networking expert or a hundred year old professor of computer science you’re lost.

What now? What is the most common and simplest HTTP client? It’s curl, of course. But cURL --verbose output does not contain HTTP Request message body:

$ curl -s -v -d "foo=bar" http://curltraceparser.apiary.io/shopping-cart
> POST /shopping-cart HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5
> Host: curltraceparser.apiary.io
> Accept: */*
> Content-Length: 7
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 7 out of 7 bytes
< HTTP/1.1 201 Created
...

The solution

Did you know that cURL can save whole raw HTTP communication to a trace file? Unfortunately the trace file format is not really human friendly.

That why we have created and open-sourced our simple parser for curl --trace option. So from now on, anytime you want to see a raw and pristine HTTP message, this is the simplest way to do it:

$ npm install -g curl-trace-praser
$ curl --trace - -s -d "foo=bar" http://curltraceparser.apiary.io/shopping-cart | curl-trace-parser
> POST /shopping-cart HTTP/1.1
> ser-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5
> Host: curltraceparser.apiary.io
> Accept: */*
> Content-Length: 7
> Content-Type: application/x-www-form-urlencoded
>
> foo=bar
>

< HTTP/1.1 201 Created
< Content-Type: application/json
< Date: Mon, 22 Jul 2013 13:24:33 GMT
< X-Apiary-Ratelimit-Limit: 120
< X-Apiary-Ratelimit-Remaining: 118
< Content-Length: 50
< Connection: keep-alive
<
< { "status": "created", "url": "/shopping-cart/2" }

There it is! Let’s introduce ourselves. This is the HTTP message.