-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstarlette_app.py
executable file
·42 lines (37 loc) · 1.2 KB
/
starlette_app.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
#!/usr/bin/env python
from starlette.applications import Starlette
from starlette.responses import JSONResponse, PlainTextResponse
from starlette.routing import Route
import uvicorn
async def hello(request):
return JSONResponse({"hello":"world"})
async def big_response(request):
return PlainTextResponse('''{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}''')
routes = [
Route('/ping', endpoint=hello),
Route('/pong', endpoint=big_response),
]
app = Starlette(routes=routes, debug=True)
if __name__ == "__main__":
uvicorn.run('starlette_app:app', host='0.0.0.0', port=5000, reload=True)