Skip to content

Instantly share code, notes, and snippets.

@kamilglod
Created May 20, 2020 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamilglod/b96065c2e38ee62081c77578615d8bdb to your computer and use it in GitHub Desktop.
Save kamilglod/b96065c2e38ee62081c77578615d8bdb to your computer and use it in GitHub Desktop.
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