To try this example, you need GNU make and git in your PATH.
If you don’t have HTTPie installed, use the appropriate cURL commands instead.
To build the example, run the following command:
makeTo start the release in the foreground:
./_rel/rest-stream-response-example/bin/rest-stream-response-example consoleNote: The previous command also starts an Erlang console.
To start the app and an LFE shell:
lfe -pa ebin -pa deps/*/ebin -s rest-stream-response # make devPoint your browser at http://localhost:8080, or use http to see the rows
arriving one at a time every half second.
This example simulates streaming a large amount of data from a data store one record at a time in CSV format. It also uses a constraint to ensure that the last segment of the route is an integer.
http -vS :8080GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/0.9.3HTTP/1.1 200 OK
connection: close
content-type: text/csv
date: Wed, 06 Jan 2016 06:49:34 GMT
server: Cowboy
transfer-encoding: identityOne every half second:
Dw8LBBQA,1,46
GAoZChcG,1,24
AQkCAhQQ,1,22
…
http -vS :8080/5GET /4 HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/0.9.3HTTP/1.1 200 OK
connection: close
content-type: text/csv
date: Wed, 06 Jan 2016 06:51:20 GMT
server: Cowboy
transfer-encoding: identityOne every half second:
BBEBEQAU,4,49
ABcFDxcE,4,42
FA8QDwEZ,4,40
…
http -vS :8080/fooGET /foo HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/0.9.3HTTP/1.1 404 Not Found
content-length: 0
date: Wed, 06 Jan 2016 06:53:38 GMT
server: Cowboy