> For the complete documentation index, see [llms.txt](https://neomatrixcode.gitbook.io/merly/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://neomatrixcode.gitbook.io/merly/guide/bodyparser.md).

# Body parser

## formats

If you want to format the data sent in the body by the client to an endpoint, to be used in a certain format within the body of the function that processes said request, you should only use the formats dictionary.

To this dictionary, the value of the Content-Type of the sent data will be added as a key and it will be associated with a custom method, which must necessarily receive a string and return a single value, which will be the data already processed.

```julia
function tojson(data::String)
   return JSON.parse(data)
end

formats["application/json"] = tojson

```

Once this is done, when the server is executed, the data with the respective Content-Type specified previously will be processed by the custom function and sent to the function associated with the determined endpoind.

```julia
Post("/data", (request,HTTP)-> begin

  HTTP.Response(200
          , HTTP.mkheaders(["Content-Type" => "text/plain"])
          , body=string("I did something! ", request.body["query"]))

end)

```

<mark style="color:green;">`POST`</mark> `/data`

#### Headers

| Name         | Type   | Description      |
| ------------ | ------ | ---------------- |
| Content-Type | string | application/json |

#### Request Body

| Name  | Type   | Description |
| ----- | ------ | ----------- |
| query | string | text        |

{% tabs %}
{% tab title="200 " %}

```
"I did something! text"
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://neomatrixcode.gitbook.io/merly/guide/bodyparser.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
