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.

Forward Slash at end of a router URL Problem

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.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

router = APIRouter(
    prefix="/care_line_people",
    tags=["CareLinePeople"],
    responses={404: {"description": "Not found"}},
)


@router.get('/add_identification_to_person')
def add_identification_to_person():
    return '2'

@router.get('/add_identification_to_person_teste/')
def add_identification_to_person():
    return '3'

Description

If I call bot endpoints locally it behaves as expected. Only method GET to the exact correct path, returns me what I want. Call GET with ‘/add_identification_to_person’, returns 2 and call ‘/add_identification_to_person_teste/’ (with dash incluse) returns 3. If I call GET with ‘/add_identification_to_person/’ it returns me 2 and if I call POST with ‘/add_identification_to_person’ it returns {details: method not allowed}.

The problema appears when I run this aplication on a EC2 in AWS configured with an Elastic Beanstalk (with Docker) and a Load Balancer where if I call any HTTP METHOD in a path ending with a ‘/’ it returns me that function normaly. So, if I call POST ‘/add_identification_to_person_teste’ it returns 3 and if a call ‘/add_identification_to_person/’ it returns 2.

I could found an explanation for this problem.

Operating System

Linux

Operating System Details

Both machines, mine and AWS are linux x86.

FastAPI Version

fastapi==0.79.0

Python Version

3.8

Additional Context

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
JafetGuerracommented, Aug 26, 2022

@four43 sorry I wrote it fast and I didnt write it properly. It is a foward slash indeed

0reactions
four43commented, Aug 26, 2022

FYI that is a “forward slash” not a dash “-”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should You Have a Trailing Slash at the End of URLs? - Ahrefs
A trailing slash is a forward slash (“/”) placed at the end of a URL such as domain.com/ or domain.com/page/. But should you...
Read more >
Problem with accessing url with space followed by slash
A forward slash in a url indicates a subdirectory so in your example, the webserver will interpret VT xxx/xx as the xx file...
Read more >
Encoded forward slash (%2F) in parameter not routing correctly
Passing an encoded forward slash as a route parameter will be interpreted by the router as a decoded forward slash. Steps To Reproduce:...
Read more >
Trailing slash on end url - Need Help
As I wrote, I need a slash at the end. If I clear the cache, the problem is the same, routing variables are...
Read more >
URL trailing slash — Gatsby - DEV Community ‍ ‍
URL trailing slash can present some problems for Gatsby websites that probably ... Trailing slash is a forward slash / at the end...
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