Created
May 20, 2020 11:38
-
-
Save kamilglod/b96065c2e38ee62081c77578615d8bdb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import asdict | |
import uvicorn | |
from starlette.applications import Starlette | |
from starlette.routing import Route | |
from starlette.responses import UJSONResponse | |
from src.repo.users import get_user, get_users | |
async def users(request): | |
return UJSONResponse([asdict(row) for row in await get_users()]) | |
async def user(request): | |
return UJSONResponse(asdict(await get_user())) | |
routes = [ | |
Route("/users", endpoint=users), | |
Route("/user/{id}", endpoint=user), | |
] | |
app = Starlette(routes=routes) | |
if __name__ == "__main__": | |
uvicorn.run(app, host="localhost", port=5000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment