Skip to content

Latest commit

 

History

History
112 lines (82 loc) · 2.2 KB

README.md

File metadata and controls

112 lines (82 loc) · 2.2 KB

Example project

The example project implements a sample REST API with golax.

Up and running

How to build and run:

make example && ./_vendor/bin/example

The API

It is a CRUD over a users collection.

List user ids GET /service/v1/users/

Command:

curl -i http://localhost:8000/service/v1/users/

Result:

HTTP/1.1 200 OK
Date: Sun, 31 Jan 2016 21:15:50 GMT
Content-Length: 8
Content-Type: text/plain; charset=utf-8

[1,2,3]

Create new user POST /service/v1/users/

Command:

curl -i http://localhost:8000/service/v1/users/ --data '{"name":"Oscar"}'

Result:

HTTP/1.1 201 Created
Date: Sun, 31 Jan 2016 21:32:38 GMT
Content-Length: 9
Content-Type: text/plain; charset=utf-8

{"id":4}

Get a user GET /service/v1/users/{user_id}

Command:

curl -i http://localhost:8000/service/v1/users/4

Result:

HTTP/1.1 200 OK
Date: Sun, 31 Jan 2016 21:33:36 GMT
Content-Length: 43
Content-Type: text/plain; charset=utf-8

{"name":"Oscar","age":0,"introduction":""}

Modify a user POST /service/v1/users/{user_id}

Command:

curl -i http://localhost:8000/service/v1/users/4 \
--data '{"age":70, "introduction": "Hello, I like golax"}'

Result:

HTTP/1.1 200 OK
Date: Sun, 31 Jan 2016 21:35:12 GMT
Content-Length: 0
Content-Type: text/plain; charset=utf-8

Delete a user DELETE /service/v1/users/{user_id}

Command:

curl -i -X DELETE http://localhost:8000/service/v1/users/1

Result:

HTTP/1.1 200 OK
Date: Sun, 31 Jan 2016 21:36:40 GMT
Content-Length: 0
Content-Type: text/plain; charset=utf-8