Send Data via Body of HTTP Request
Last updated
Last updated
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:
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:
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
Note that the payload
dictionary can be referenced normally by key
Postman Results: