Skip to content
Discussion options

You must be logged in to vote

That is very helpful, thank you @frankie567 .

For completeness, this is the final code which meets my requirements:

from fastapi import Request, FastAPI, Form, HTTPException
import logging

app = FastAPI()

@app.post("/post_name")
async def parse_data(request: Request):
    data_body = await request.form()
    logging.info(data_body)  
    if "first_name" not in data_body or "last_name" not in data_body:
        raise HTTPException(422, "Missing fields")
    first_name = data_body["first_name"]
    last_name = data_body["last_name"]
    return first_name + last_name

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
2 participants
Converted from issue

This discussion was converted from issue #3857 on February 27, 2023 22:28.