encode / starlette

The little ASGI framework that shines. 🌟
https://www.starlette.io/
BSD 3-Clause "New" or "Revised" License
10.32k stars 948 forks source link

How to change the value of request body? #2550

Closed Songjiadong closed 8 months ago

Songjiadong commented 8 months ago

I want to change the request body value of simple_invoke,would you give me a demo? I can't change request body value. Based on my experience with Java and C #, I believe this can be solved, but I am not very familiar with FastAPI . Can you help me? Thanks!

def add_one(x: int) -> int:
    """Add one to the given number."""
    return x + 1

chain = RunnableLambda(add_one)

api_handler = APIHandler(chain, path="/simple")

# First register the endpoints without documentation
@app.post("/simple/invoke", include_in_schema=False)
async def simple_invoke(request: Request) -> Response:
    """Handle a request."""
    ### NOTE: I want change the value of request body at this position !!!! for example:  if  value of request body equals '1',I want change it to '100'
    return await api_handler.invoke(request)

[!IMPORTANT]

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.

Fund with Polar