Skip to content

Tag: fastapi

How to redirect to dynamic URL inside a FastAPI endpoint?

I’m doing a feature where the user on their profile page makes changes (not related to the user model). Everything is implemented through static HTML templates. I need the user to click on the button and return to the same page (i.e., their profile page) after processing the request. Html template endpo…

FastAPI serving static files through symlinks

I have mounted the static directory in my FastAPI app using the following code: If I have a symlink pointing to a path outside the app folder, e.g. The FastAPI application can recognize the URL xyz.com/public/index.html, but it can’t recognize xyz.com/public/data. Is this doable? Unfortunately, I cannot…

How to get current path in FastAPI with domain?

I have a simple route as below that written in FastAPI, How can I get the current path “programmatically” with, domain (some-domain.com) path (/foo/bar/{rand_int}/foo-bar/) and query parameters (?somethig=foo) Answer We can use the Request.url-(starlette doc) API to get the various URL properties.…

Problem installing Uvicorn in Termux, Android

I am trying to install and run FastAPI in Termux. I install FastAPI successfully. But when I try to install uvicorn with pip install “uvicorn[standard]” I get this error. I can’t paste the error here, because Stackoverflow identifies it as spam, here is a link However, I successfully install…

FastAPI Textarea OpenAPI for Form Data

I am using Form Data format for APIs. The thing is how I am going to make OpenAPI input being larger by using textarea? Answer i’ve hacked. my way is when specific field name, change input(type=text) to textarea. first, you serve self-hosting javascript and css for docs. https://fastapi.tiangolo.com/adv…

How to validate request body in FastAPI?

I understand that if the incoming request body misses certain required keys, FastAPI will automatically raise 422 unserviceable entity error. However, is there a way to check the incoming request body by myself in the code and raise a 400 bad request if if misses required names? For example, say I have this m…