For the complete documentation index, see llms.txt. This page is also available as Markdown.

Send Data via Body of HTTP Request

We are using Postman to create the HTTP Request with Body data

For additional info on how Postman works click here

  • Go to the Body of the POST request

  • Go to RAW under the Body section and usually you want to select JSON

Note: You can use other types as well depending on needs. Such as XML, JS, Text

JSON works very similar to a python dictionary data structure

How it would look:

Now that we have our HTTP packet set up, we can move on to the FastAPI code

  • You will have to import the Body parameter from fastapi.params

  • Once this is imported you are able to set up the function so that it converts the JSON sent via HTTP request to a python dictionary and stores it into the payload variable

  • Then you can return the variable

Full Code:

Alternatively you can print this to the screen:

Once you run this via uvicorn and send the packet via postman you should get the dictionary printed in the terminal:

  • Note on line 8 that the dictionary got printed

Even better you could return the results via an f string referencing the dictionary key

  • Note that the payload dictionary can be referenced normally by key

Postman Results:

Last updated