2013-09-07 16:18:51 +02:00
|
|
|
Basic authorization example using REST
|
|
|
|
======================================
|
2013-01-30 00:30:05 +04:00
|
|
|
|
2013-10-22 09:14:32 +02:00
|
|
|
To try this example, you need GNU `make` and `git` in your PATH.
|
2013-01-30 00:30:05 +04:00
|
|
|
|
2013-09-07 16:18:51 +02:00
|
|
|
To build the example, run the following command:
|
2013-01-30 00:30:05 +04:00
|
|
|
|
2013-09-07 16:18:51 +02:00
|
|
|
``` bash
|
|
|
|
$ make
|
2013-01-30 00:30:05 +04:00
|
|
|
```
|
2013-09-07 16:18:51 +02:00
|
|
|
|
|
|
|
To start the release in the foreground:
|
|
|
|
|
|
|
|
``` bash
|
2014-06-30 10:14:05 +02:00
|
|
|
$ ./_rel/rest_basic_auth_example/bin/rest_basic_auth_example console
|
2013-01-30 00:30:05 +04:00
|
|
|
```
|
|
|
|
|
2013-09-07 16:18:51 +02:00
|
|
|
Then point your browser at [http://localhost:8080](http://localhost:8080).
|
2013-01-30 00:30:05 +04:00
|
|
|
|
2013-09-07 16:18:51 +02:00
|
|
|
Example output
|
|
|
|
--------------
|
|
|
|
|
|
|
|
Request with no authentication:
|
2013-01-30 00:30:05 +04:00
|
|
|
|
|
|
|
``` bash
|
|
|
|
$ curl -i http://localhost:8080
|
|
|
|
HTTP/1.1 401 Unauthorized
|
|
|
|
connection: keep-alive
|
|
|
|
server: Cowboy
|
|
|
|
date: Sun, 20 Jan 2013 14:10:27 GMT
|
|
|
|
content-length: 0
|
2013-09-07 16:18:51 +02:00
|
|
|
www-authenticate: Basic realm="cowboy"
|
2013-01-30 00:30:05 +04:00
|
|
|
```
|
|
|
|
|
2013-09-07 16:18:51 +02:00
|
|
|
Request with authentication:
|
|
|
|
|
2013-01-30 00:30:05 +04:00
|
|
|
``` bash
|
|
|
|
$ curl -i -u "Alladin:open sesame" http://localhost:8080
|
|
|
|
HTTP/1.1 200 OK
|
|
|
|
connection: keep-alive
|
|
|
|
server: Cowboy
|
|
|
|
date: Sun, 20 Jan 2013 14:11:12 GMT
|
|
|
|
content-length: 16
|
|
|
|
content-type: text/plain
|
|
|
|
|
|
|
|
Hello, Alladin!
|
|
|
|
```
|