Skip to content

Latest commit

 

History

History

rest-hello-world

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

REST hello world example

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.

Building

To build the example, run the following command:

make

Starting

Release

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.

LFE

To start the app and an LFE shell:

lfe -pa ebin -pa deps/*/ebin -s rest-hello-world # make dev

Usage

Point your browser at http://localhost:8080, or use http to see the chunks arriving one at a time every second.

Example output

Request HTML

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>

Request JSON

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!"
}

Request plain text

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!