comparison wsgraph/web.py @ 2:7a3b21cafc00

start to sketch out REST API
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 09 Dec 2012 10:40:17 -0800
parents cfcfa093e4b4
children 42f484880808
comparison
equal deleted inserted replaced
1:5abe00d24a2f 2:7a3b21cafc00
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 """ 3 """
4 web handler for WSGraph 4 web handler for WSGraph
5
6 Formatters are keyed off of:
7 - (TODO)
8
9 formatters = {0: {
10 }
11 """ 5 """
12 6
13 import json 7 import json
14 from webob import Request, Response, exc 8 from webob import Request, Response, exc
15 9
44 import pdb; pdb.set_trace() 38 import pdb; pdb.set_trace()
45 39
46 # HTTP methods 40 # HTTP methods
47 41
48 def GET(self, request): 42 def GET(self, request):
49 """respond to a GET request""" 43 """
44 respond to a GET request
45
46 Formatters are keyed off of
47
48 formatters = {0: {
49 }
50
51 API:
52
53 ?format=<format>
54
55 """
50 56
51 segments = self.path_segments(request) 57 segments = self.path_segments(request)
52 58
53 # formatter 59 # formatter
54 formatter = self.formatters[len(segments)] 60 formatter = self.formatters[len(segments)]
55 return Response(content_type='text/plain', 61 return Response(content_type='text/plain',
56 body="WSGraph") 62 body="WSGraph")
57 63
58 def POST(self, request): 64 def POST(self, request):
59 """respond to a POST request""" 65 """
60 raise NotImplementedError 66 respond to a POST request
67
68 API:
69
70 ?update :
71 """
72
73 return exc.HTTPSeeOther('/') # TODO: /path/to/self
61 74
62 def HEAD(self, request): 75 def HEAD(self, request):
63 """respond to a HEAD request""" 76 """respond to a HEAD request"""
64 raise NotImplementedError 77 raise NotImplementedError
65 78