HomeToolsAbout

In-Memory

@app.get( "/image", # Set what the media type will be in the autogenerated OpenAPI specification. # fastapi.tiangolo.com/advanced/additional-responses/#additional-media-types-for-the-main-response responses = { 200: { "content": {"image/png": {}} } }, # Prevent FastAPI from adding "application/json" as an additional # response media type in the autogenerated OpenAPI specification. # https://github.com/tiangolo/fastapi/issues/3258 response_class=Response ) def get_image() image_bytes: bytes = generate_cat_picture() # media_type here sets the media type of the actual response sent to the client. return Response(content=image_bytes, media_type="image/png")

AboutContact