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:
make
To start the release in the foreground:
./_rel/rest-hello-world-example/bin/rest-hello-world-example console
Note: The previous command also starts an Erlang console.
To start the app and an LFE shell:
lfe -pa ebin -pa deps/*/ebin -s rest-hello-world # make dev
Point your browser at http://localhost:8080, or use http
to see the chunks
arriving one at a time every second.
http -v :8080
GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/0.9.2
HTTP/1.1 200 OK
content-length: 139
content-type: text/html
date: Mon, 21 Sep 2015 23:58:39 GMT
server: Cowboy
vary: accept
<html>
<head>
<meta charset="utf-8">
<title>REST Hello world!</title>
</head>
<body>
<p>REST Hello world as HTML!</p>
</body>
</html>
http -vj :8080
GET / HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Type: application/json
Host: localhost:8080
User-Agent: HTTPie/0.9.2
HTTP/1.1 200 OK
content-length: 24
content-type: application/json
date: Tue, 22 Sep 2015 00:00:00 GMT
server: Cowboy
vary: accept
{
"rest": "Hello World!"
}
http -v :8080 Accept:text/plain
GET / HTTP/1.1
Accept: text/plain
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/0.9.2
HTTP/1.1 200 OK
content-length: 25
content-type: text/plain
date: Tue, 22 Sep 2015 00:01:14 GMT
server: Cowboy
vary: accept
REST Hello World as text!