Skip to content

Latest commit

 

History

History

rest-basic-auth

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Basic authorization example using REST

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-basic-auth-example/bin/rest-basic-auth-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-basic-auth # make dev

Usage

Point your browser at http://localhost:8080.

Example output

Request with no authentication

http -v :8080
GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/0.9.3
HTTP/1.1 401 Unauthorized
content-length: 0
date: Mon, 04 Jan 2016 06:08:06 GMT
server: Cowboy
www-authenticate: Basic realm="cowboy"

Request with authentication

http -va 'Aladdin:open sesame' :8080
GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/0.9.3
HTTP/1.1 200 OK
content-length: 16
content-type: text/plain
date: Mon, 04 Jan 2016 06:18:37 GMT
server: Cowboy
Hello, Aladdin!