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.

How do I handle multiple slashes in the URL path leading, mid-path or trailing, similar to non strict slashes in Flask.

See original GitHub issue

First check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn’t find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google “How to X in FastAPI” and didn’t find any information.
  • I already read and followed all the tutorial in the docs and didn’t find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.
  • After submitting this, I commit to one of:
    • Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.
    • I already hit the “watch” button in this repository to receive notifications and I commit to help at least 2 people that ask questions in the future.
    • Implement a Pull Request for a confirmed bug.

Example

Here’s a self-contained, minimal, reproducible, example with my use case:

from fastapi import FastAPI

app = FastAPI()


@app.get("/hello/x")
def read_root():
    return {"Hello": "World"}

Description

curl http://localhost:8000/hello/x --> is OK
curl http://localhost:8000///hello///x --> throws 404

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
Kludexcommented, Oct 20, 2020

@NightMachinary

from fastapi import FastAPI

from someplace import HttpUrlRedirectMiddleware

app = FastAPI()
app.add_middleware(HttpUrlRedirectMiddleware)
1reaction
tiangolocommented, Nov 9, 2022

Thanks for the help and discussion here everyone!

And thanks for coming back to close the issue @mehmetg

Sorry for the long delay! 🙈 I wanted to personally address each issue/PR and they piled up through time, but now I’m checking each one in order.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trailing slash triggers 404 in Flask path rule - python
Your /users route is missing a trailing slash, which Werkzeug interprets as an explicit rule to not match a trailing slash. Either add...
Read more >
10.3. Routing — Fundamentals of Web Programming
It's similar to a folder in a file system. If you access the URL without a trailing slash, Flask redirects you to the...
Read more >
Trailing slash rule. Is this behaviour flask specific or ...
I just made a no brainer rule to always add trailing slash to every route... is this okay or this should be used...
Read more >
Trailing slash on URLs / Navigation issue
Solved: Two questions here related to URL structure. When we migrated our website to Hubspot, a decision was made to add trailing slashes...
Read more >
4. Routing — Flask API - GitHub Pages
In that sense, it is similar to a folder on a filesystem. Accessing it without a trailing slash will cause Flask to redirect...
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