-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
40 lines (31 loc) · 1.11 KB
/
example.py
File metadata and controls
40 lines (31 loc) · 1.11 KB
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
36
37
38
39
40
import siesta.application
import siesta.routers
class IndexHandler(siesta.routers.Resource):
def get(self, request):
return (200, [('Content-Type', 'text/html')], 'index!')
class CatsHandler(siesta.routers.Resource):
def get(self, request):
return (200, [('Content-Type', 'text/html')], 'collection of cats!')
class CatHandler(siesta.routers.Resource):
def get(self, request):
return (200, [('Content-Type', 'text/html')], 'get cat!')
def put(self, request):
return (200, [('Content-Type', 'text/html')], 'put cat!')
class DogHandler(siesta.routers.Resource):
def get(self, request):
return (200, [('Content-Type', 'text/html')], 'get dog!')
router = siesta.routers.NestedResourceRouter(
(IndexHandler(), {
'cats': (CatsHandler(), {
'*': CatHandler(),
}),
'dogs': (None, {
'*': DogHandler()
}),
}))
app = siesta.application.application(router)
if __name__ == "__main__":
from werkzeug.serving import run_simple
run_simple('localhost', 4000, app)
# curl http://localhost:4000/cats/15
# => 'get cat!'