@@ -20,7 +20,7 @@ The only glitch is that cURL `--trace` saves data in [its custom format][gist],
2020$ curl --trace - http://httpbin.org/ip | curl-trace-parser
2121```
2222
23- ## Example
23+ ## Sample API
2424
2525We will be using this [ sample API] [ apiarydoc ] created with the [ Apiary.io mock server] ( http://apiary.io ) to demonstrate tracing an HTTP communication and the use of the cURL trace parser.
2626
@@ -45,51 +45,89 @@ Note this cURL example is copied and pasted from [Apiary interactive API documen
4545
4646[ example ] : http://docs.curltraceparser.apiary.io/#get-%2Fshopping-cart
4747
48- ## Parse the trace file from command line
48+ ## Examples
49+
50+ ### ` --raw ` format
51+
52+ The output is ASCII representation of a raw [ HTTP message] [ message ] with few modifications:
53+
54+ - Request line begins with ` > `
55+ - Response line begins with ` < `
56+ - Request and Response is delimited by CR+LF
57+ - Both Request and Response are terminated by an extra trailing LF
58+
59+ Note: This is little bit tricky because HTTP RFC does not have declared delimiter for Request and Response, for obvious reasons.
4960
5061``` bash
51- $ cat tracefile | curl-trace-parser
52- > GET /shopping-cart HTTP/1.1
62+ $ cat tracefile | curl-trace-parser --raw
63+ > POST /shopping-cart HTTP/1.1
5364> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5
5465> Host: curltraceparser.apiary.io
5566> Accept: * /*
56- >
67+ > Content-Type: application/json
68+ > Content-Length: 39
5769>
70+ > { " product" :" 1AB23ORM" , " quantity" : 2 }
5871
59- < HTTP/1.1 200 OK
72+ < HTTP/1.1 201 Created
6073< Content-Type: application/json
61- < Date: Sun, 21 Jul 2013 13:23:55 GMT
74+ < Date: Tue, 30 Jul 2013 11:32:30 GMT
6275< X-Apiary-Ratelimit-Limit: 120
6376< X-Apiary-Ratelimit-Remaining: 119
64- < Content-Length: 119
77+ < Content-Length: 50
6578< Connection: keep-alive
6679<
67- < { " items" : [
68- < { " url" : " /shopping-cart/1" , " product" :" 2ZY48XPZ" , " quantity" : 1, " name" : " New socks" , " price" : 1.25 }
69- < ] }
80+ < { " status" : " created" , " url" : " /shopping-cart/2" }
81+ ` ` `
82+
83+ # ## `--blueprint` format
84+
85+ The output is HTTP Request and Response in the [API blueprint format](http://apiblueprint.org) which is the superset of markdown.
86+
87+ ` ` `
88+ $ cat tracefile | ./bin/curl-trace-parser --blueprint
89+ # POST /shopping-cart
90+ + Request
91+ + Headers
92+
93+ User-Agent:curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5
94+ Host:curltraceparser.apiary.io
95+ Accept:* /*
96+ Content-Type:application/json
97+ Content-Length:39
98+
99+ + Body
100+
101+ { " product" :" 1AB23ORM" , " quantity" : 2 }
102+
103+ + Response 201
104+ + Headers
105+
106+ Content-Type:application/json
107+ Date:Tue, 30 Jul 2013 11:32:30 GMT
108+ X-Apiary-Ratelimit-Limit:120
109+ X-Apiary-Ratelimit-Remaining:119
110+ Content-Length:50
111+ Connection:keep-alive
112+
113+ + Body
114+
115+ { " status" : " created" , " url" : " /shopping-cart/2" }
116+
70117` ` `
71118
72- # # Parse the trace file using Node.JS
119+ Note: This format does not expect any CR+LF in body
120+
121+ # ## Parse the trace to raw HTTP file using Node.JS
73122
74123` ` ` javascript
75124var fs = require(' fs' );
76125var parser = require(' curl-trace-parser' );
77126fs.readFile(' ./tracefile' , ' utf8' , function (err,trace) {
78- console.log(parser.parseToString (trace));
127+ console.log(parser.parse (trace));
79128})
80129` ` `
81130
82- # # Output format
83-
84- The output is ASCII representation of a raw [HTTP message][message] with few modifications:
85-
86- - Request line begins with ` > `
87- - Response line begins with ` < `
88- - Request and response is delimited by CR+LF
89- - Both Request and Response are terminated by an extra trailing LF
90-
91- Note: This is little bit tricky because HTTP RFC does not have declared delimiter for Request and Response, for obvious reasons.
92-
93131# # Output format reverse parser
94132
95133` ` ` javascript
0 commit comments