Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
How should a fastapi response be formatted?

I am new to web communication. I use ubuntu and try to learn fastapi. However, I think it is really hard to understand how to format the response that I intend to send back to the client.

What are the rules for the responses that are to be sent back? And if you want to send back a customized answer - for example two image files - how is that encoded?

Thus far, I only managed to get something like this to work:

@app.post("/")
async def post_test():
    print("Bonjour")
    return {"I don't know what options I have to format this response and for example return images :( "}

Please help with this!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If not done already, I encourage you to read the full fastAPI tutorial which is very clear and step by step. Generally speaking a fastAPI app will convert the object returned by your function into a json string in the HTTP response.

You can use pydantic schemas in your responses because pydantic handles the conversion to json for you.

As said in other answers, you can return the url to a file, or you can return the file directly using a starlette FileResponse.

from starlette.responses import FileResponse

@app.get("/my_file")
async def download_file(self):
    return FileResponse(path="my_file.png", filename="my_file", media_type="image/png")
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda