awtkns / fastapi-crudrouter

A dynamic FastAPI router that automatically creates CRUD routes for your models
https://fastapi-crudrouter.awtkns.com
MIT License
1.37k stars 155 forks source link

Exemple in documentation doesnot work as is #90

Open slamer59 opened 3 years ago

slamer59 commented 3 years ago

https://fastapi-crudrouter.awtkns.com/routing

"Working"

from pydantic import BaseModel
from fastapi import FastAPI
from fastapi_crudrouter import MemoryCRUDRouter as CRUDRouter

class Potato(BaseModel):
    id: int
    color: str
    mass: float

app = FastAPI()
router = CRUDRouter(schema=Potato)

@router.get('')
def overloaded_get_all():
    return 'My overloaded route that returns all the items'

@router.get('/{item_id}')
def overloaded_get_one():
    return 'My overloaded route that returns one item'

app.include_router(router)

Is it possible to provide an exemple to show what to do with MemoryCRUDRouter instead of a string ? Regards

awtkns commented 3 years ago

@slamer59 thanks for this! Did you want to submit this as a PR? If not I can update it :)

I agree with you, some more detailed docs for the memory CrudRouter would be useful.

slamer59 commented 3 years ago

@awtkns i can do !

What would be great is that we include exemple with get and post accessing with in Memory backend.

What do you think ?

Unfortunately I don't know how to do. If you give the exemple, I write the full doc.

Thanks !

slamer59 commented 3 years ago

I don't know if it a good practice but we can access router models with:

@router.get('')
def overloaded_get_all():
    return router.models

@router.get('/{item_id}')
def overloaded_get_one(item_id: int):
    return router.models[item_id]

is working.

@awtkns tell me if I add it like that in the documentation or not ?

Thanks :)

awtkns commented 3 years ago

Sorry for taking awhile to reply. I think that would be add good thing to also add, it could definitely be useful :)

Is it ok to close this now @slamer59 ?

slamer59 commented 3 years ago

Yes me too. Do you have time to provide me some snippet for it ? Not much time on my side but I can try.