question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Routed paths must always start with /

See original GitHub issue

Hi

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:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
tiangolocommented, Aug 26, 2019

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.

0reactions
jaddisoncommented, Aug 24, 2019

It does seem sort of awkward that using prefix prevents ‘trailing slash’ naked endpoints, as OP mentioned.

Good: /cats Bad: /cats/

(subjectively speaking)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found