Skip to content
Advertisement

Tag: fastapi

I want to change api response json in fastapi | pydantic

I am new in fastapi and please help me! I got an validation error when I change the default API response comes when I use response_model in fastAPI. The default API response is simple json like object from response_model. user.py schemas.py Now, when I run this code it gives me errors like below mentioned. Below is the output i want:-

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 endpoints.py profile.py But I can’t find anywhere how to

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 use FileResponse due to the blob size being too large. I want to

405 method not allowed when using ‘put’, but success with ‘get’, why?

I’m learning FastAPI from the official documentation. When I try running the first example from https://fastapi.tiangolo.com/tutorial/body-multiple-params/ and pasted the URL http://127.0.0.1:8000/items/35 in the browser, my server sends a message 405 Method not allowed Example code from the link is like below, I understand q and item parameters are optional in this example, so think it can respond with only item_id

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. To get the absolute URL, we need to use the Request.url._url private API , as below

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 installed it with pip install uvicorn. But when I try uvicorn main:app

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/advanced/extending-openapi/#self-hosting-javascript-and-css-for-docs. second, you change javascript source code like this. you can hack css

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 model and schema: The POST endpoint to

Advertisement