Closed jymchng closed 1 year ago
Hello, @jymchng thanks for reporting this issue I created an API that is able to get a hero by its name. Check it here https://github.com/jonra1993/fastapi-alembic-sqlmodel-async/commit/64514006db09c992df9d09279f2ebb7319c5a8b5
The issue was caused because the get route for id and the name were the same @router.get("/{hero_id}")
and @router.get("/{hero_name}")
so it thought that name was an id. This is something tricky of fastapi and the solution was to make routes different like this
Please check it and let me know our feedback.
Hi, thanks for creating such a powerful and useful template!
I am attempting to retrieve a
hero
by itsname
, e.g. 'spiderman'.I have created a record under the
Hero
table withname
='spiderman'.The code for the API to retrieve
hero
vianame
is:Using the Swagger UI and upon execution, I get the following:![image](https://user-images.githubusercontent.com/27895426/219934437-27912f17-3ac2-43a0-a978-f41d85921cd0.png)
The codes for the function
get_heroe_by_name
is as follows:Basically, I have took your template and attempted to write an API to get a
hero
by itsname
but failed to do so.Thank you.