the api docs url (http://127.0.0.1:8000/docs) , if have a slash in the end(just like http://127.0.0.1:8000/docs/ ), will not found 404.
"GET /docs/ HTTP/1.1" 404 Not Found
i think it's not a bug, couse /path/ it's like a dir, but not endpoint
This is an issue with starlette. I'm not 100% sure, but I think starlette may recently fixed this so you get a redirect to remove the / (I believe it has supported adding the / with a redirect for a while now).
Either way, if you want to ensure it works both ways, you can specify docs_url="/docs/?" in when creating the FastAPI instance.
This is actually a starlette issue; I am not 100% sure but I think a recent commit changed the behavior so by default you'll get a redirect. (It has worked to go from /docs to /docs/ for a while, but I think the reverse was only recently added.)
At any rate, you can manually specify you want to allow both via FastAPI(docs_url="/docs/?").
Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.
Thanks for the help @dmontagu ! :tada:
Most helpful comment
This is an issue with starlette. I'm not 100% sure, but I think starlette may recently fixed this so you get a redirect to remove the
/(I believe it has supported adding the/with a redirect for a while now).Either way, if you want to ensure it works both ways, you can specify
docs_url="/docs/?"in when creating theFastAPIinstance.