File: app.py

package info (click to toggle)
python-restless 2.0.1-5~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 472 kB
  • sloc: python: 1,879; makefile: 149
file content (35 lines) | stat: -rw-r--r-- 738 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import tornado.ioloop
from tornado import web, gen
from restless.tnd import TornadoResource

class PetResource(TornadoResource):
    def prepare(self):
        self.fake_db = {
            {
                "id": 1,
                "name": "Mitti",
                "type": "dog"
            },
            {
                "id": 2,
                "name": "Gary",
                "type": "cat"
            }
        }

    @gen.coroutine
    def list(self):
        raise gen.Return(self.fake_db)


routes = [
    (r'/pets', PetResource.as_list()),
    (r'/pets/([^/]+)', PetResource.as_detail())
]

app = web.Application(routes, debug=True)

if __name__ == '__main__':
    app.listen(8001)
    tornado.ioloop.IOLoop.instance().start()