> For the complete documentation index, see [llms.txt](https://docs.arkannis.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.arkannis.net/programming/python/frameworks/fastapi/send-data-via-body-of-http-request.md).

# Send Data via Body of HTTP Request

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

{% hint style="info" %}
For additional info on how Postman works [click here](/programming/postman.md)
{% endhint %}

* Go to the Body of the POST request

![](/files/1wgWlr5ZydtjodWZgq7T)

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

{% hint style="info" %}
Note: You can use other types as well depending on needs. Such as XML, JS, Text
{% endhint %}

![](/files/sMda5TYGYOqE9hIWxrEj)

{% hint style="info" %}
JSON works very similar to a python dictionary data structure
{% endhint %}

How it would look:

![](/files/9XqKXXlKqck91koBN6SP)

```json
{
    
    "title": "top gun", 
    "content": "check out my top gun"

}
```

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

* You will have to import the <mark style="color:green;">Body</mark> parameter from <mark style="color:purple;">`fastapi.params`</mark>

```python
from fastapi.params import Body
```

* 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 <mark style="color:purple;">`payload`</mark> variable

```python
def create_posts(payload: dict = Body(...)):
```

* Then you can return the variable

```python
def create_posts(payload: dict = Body(...)):
    return payload
```

Full Code:

```python
from fastapi.params import Body

@app.post("/createpost")
def create_posts(payload: dict = Body(...)):
    return payload
```

#### Alternatively you can print this to the screen:

```python
@app.post("/createpost")
def create_posts(payload: dict = Body(...)):

    print(payload)

    return {"message": "successfully created post"}

```

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

```bash
INFO:     Shutting down
INFO:     Waiting for application shutdown.
INFO:     Application shutdown complete.
INFO:     Finished server process [29399]
INFO:     Started server process [29594]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
{'title': 'top gun', 'content': 'check out my top gun'}
INFO:     127.0.0.1:37532 -"POST /createpost HTTP/1.1" 200 OK
```

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

```python
@app.post("/createpost")
def create_posts(payload: dict = Body(...)):

    print(payload)

    return {"new_post": f"title: {payload['title']} content: {payload['content']}"}
```

* Note that the <mark style="color:purple;">`payload`</mark> dictionary can be referenced normally by key

Postman Results:

![](/files/rq0gzy6idokzdhNUkY3c)
