-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtodolist.py
More file actions
58 lines (42 loc) · 1.04 KB
/
Copy pathtodolist.py
File metadata and controls
58 lines (42 loc) · 1.04 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import uuid
from aiohttp import web
routes = web.RouteTableDef()
def gen_id():
return str(uuid.uuid4())
default_items = [
{
'title': 'First',
'id': gen_id(),
'completed': False,
},
{
'title': 'Second',
'id': gen_id(),
'completed': True,
}
]
session = {}
@routes.get("/items")
async def get_items(request):
items = session.setdefault('items', default_items)
return web.json_response(items)
@routes.post("/items")
async def post_items(request):
items = session.setdefault('items', default_items)
item = await request.get_json()
item['id'] = gen_id()
items.append(item)
session.modified = True
return web.json_response(item)
@routes.put("/items/<item_id>")
async def put_items(request):
item = request.get_json()
# TODO: search and update
return web.json_response(item)
@routes.get("/")
async def root():
raise web.HTTPFound("/static/index.html")
app = web.Application()
app.add_routes(routes)
if __name__ == '__main__':
web.run_app(app)