Wiki

Clone wiki

rest-api-blueprint / ExampleApp

Example App

To have something to work with, the code implements a trivial contact "database" of names to emails (with comments). This database is not persisted but just held in memory. The essential capabilities are:

  • Add/remove a person from the database
  • Set/update the email address and/or comment for that person
  • Get the email address and/or comment for a person
  • List all people
  • Clear the database

Email addresses must be valid, but comment's can include anything (including non ASCII).

There are also two other "apps" (expressed as Flask blueprints) which are used to show poll testing and oauth. See the blueprints directory.

Usage

Run the server with python runserver.py. Then for example, use httpie to add a person and retrieve their email address:

$http -jv PUT localhost:5000/v1/people/tim email="timothy@foo.bar.com"
PUT /v1/people/tim HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Content-Type: application/json; charset=utf-8
Host: localhost:5000
User-Agent: HTTPie/0.3.0

{
    "email": "timothy@foo.bar.com"
}

HTTP/1.0 200 OK
Content-Length: 20
Content-Type: application/json
Date: Fri, 15 Feb 2013 15:57:01 GMT
Server: Werkzeug/0.8.3 Python/2.7.3

{
    "status": "ok"
}
$http -jv GET localhost:5000/v1/people/tim
GET /v1/people/tim HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Host: localhost:5000
User-Agent: HTTPie/0.3.0



HTTP/1.0 200 OK
Content-Length: 114
Content-Type: application/json
Date: Fri, 15 Feb 2013 15:57:53 GMT
Server: Werkzeug/0.8.3 Python/2.7.3

{
    "result": {
        "comment": null, 
        "email": "timothy@foo.bar.com", 
        "name": "tim"
    }, 
    "status": "ok"
}

Updated