Skip to content

Latest commit

 

History

History

web-server

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Static file handler 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/web-server-example/bin/web-server-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 web-server # make dev

Usage

Point your browser at http://localhost:8080 to browse the contents of the priv directory.

Example output

Request HTML

http -v :8080 Accept:text/html
GET / HTTP/1.1
Accept: text/html
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/0.9.2
HTTP/1.1 200 OK
content-length: 256
content-type: text/html
date: Sat, 02 Jan 2016 11:45:09 GMT
server: Cowboy
vary: accept
<!DOCTYPE html><html><head><title>Index</title></head><body><a href='/..'>..</a><br>
<a href='/small.mp4'>small.mp4</a><br>
<a href='/small.ogv'>small.ogv</a><br>
<a href='/test.txt'>test.txt</a><br>
<a href='/video.html'>video.html</a><br>
</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: 49
content-type: application/json
date: Sat, 02 Jan 2016 11:46:11 GMT
server: Cowboy
vary: accept
[
    "small.mp4",
    "small.ogv",
    "test.txt",
    "video.html"
]

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 406 Not Acceptable
content-length: 0
date: Sat, 02 Jan 2016 11:47:10 GMT
server: Cowboy