-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp.py
52 lines (31 loc) · 1.01 KB
/
temp.py
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
41
42
43
44
45
46
47
48
49
50
51
52
from webob import Request, Response
class API:
def __init__(self):
self.routes = {}
def __call__(self, environ, start_response):
print('called')
request = Request(environ)
response = self.handle_request(request)
return response(environ, start_response)
def route(self, path):
print('route')
def wrapper(handler):
self.routes[path] = handler
return handler
return wrapper
def handle_request(self, request):
response = Response()
for path, handler in self.routes.items():
if path == request.path:
handler(request, response)
return response
app = API()
@app.route("/home")
def home(request, response):
response.data = "Hello from the HOME page"
@app.route("/about")
def about(request, response):
response.data = "Hello from the ABOUT page"
@app.route("/hello/{name}")
def greeting(request, response, name):
response.data = f"Hello, {name}"