[Python] How to read the request body using orjson library in FastAPI?

Discussão em 'Python' iniciado por Stack, Dezembro 22, 2024.

  1. Stack

    Stack Membro Participativo

    I am writing code to receive a JSON payload in FastAPI.

    Here is my code:

    from fastapi import FastAPI, status, Request
    from fastapi.responses import ORJSONResponse
    import uvicorn
    import asyncio
    import orjson

    app = FastAPI()

    @app.post("/", status_code = status.HTTP_200_OK)
    async def get_data(request: Request):
    param = await request.json()
    return param


    However, what I want is request.json() to be used with orjson instead of the default json library of Python. Any idea how to address this problem? Please help me, thanks.

    Continue reading...

Compartilhe esta Página