Skip to content

Instantly share code, notes, and snippets.

@Goldziher
Last active January 3, 2022 13:03
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 Goldziher/982726896e60b19b312b7ec04f74acb1 to your computer and use it in GitHub Desktop.
Save Goldziher/982726896e60b19b312b7ec04f74acb1 to your computer and use it in GitHub Desktop.
Example Starlite Controller
from typing import List
from pydantic import UUID4
from starlite import Controller, Partial, get, post, put, patch, delete
from my_app.models import User
class UserController(Controller):
path = "/users"
@post()
async def create_user(self, data: User) -> User:
...
@get()
async def list_users(self) -> List[User]:
...
@patch(path="/{user_id:uuid}")
async def partially_update_user(self, user_id: UUID4, data: Partial[User]) -> User:
...
@put(path="/{user_id:uuid}")
async def update_user(self, user_id: UUID4, data: User) -> User:
...
@get(path="/{user_id:uuid}")
async def get_user(self, user_id: UUID4) -> User:
...
@delete(path="/{user_id:uuid}")
async def delete_user(self, user_id: UUID4) -> User:
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment