Routed paths must always start with /
See original GitHub issueHi
Let’s say I have the following API:
GET /accounts - list of accounts
POST /accounts - create account
GET /accounts/{id} - get account by id
DELETE /accounts/{id} - delete account
then I would make a module accounts with APIRouter
in main.py
app.include_router(accounts.router, prefix="/accounts")
and in accounts.py
router = APIRouter()
@router.get("")
def list_accounts():
...
@router.post("")
def list_accounts():
...
@router.get("/{id}")
def get_account(id:str):
...
but I’m getting an error “Routed paths must always start with /”
if I add to router “/” - then my resources will look like GET /accounts/
, POST /accounts/
(but I do not want slash at the end…)
Basically the idea is to put 5-10 methods inside module and all should start with /accounts
how should i solve this ?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
How to capture arbitrary paths at one route in FastAPI?
Show activity on this post. Since FastAPI is based on Starlette, you can use what they call "converters" with your route parameters, using...
Read more >Router in axum::routing - Rust
Add another route to the router. path is a string of path segments separated by / . Each segment can be either static,...
Read more >Rails Routing from the Outside In
Rails Routing from the Outside InThis guide covers the user-facing features of Rails routing.After reading this guide, you will know: How to interpret...
Read more >Routing
In cases where more that one route could match an incoming path, you should take care to ensure that more specific routes are...
Read more >Routing and Params
Sometimes you need a group of routes to be prefixed with some path. For example, starting all of your routes with /api/v1/ ....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you, everyone, for the discussion here!
Thanks @vitalik for the PR! More comments on the PR itself: https://github.com/tiangolo/fastapi/pull/415#issuecomment-524591290
You can now use this in FastAPI
0.36.0
with an empty path (""
). 🎉 🚀I’ll close this now, but feel free to add more comments or create new issues.
It does seem sort of awkward that using
prefix
prevents ‘trailing slash’ naked endpoints, as OP mentioned.Good:
/cats
Bad:/cats/
(subjectively speaking)