# Overview

The highest levels of API in regards to CoAP are all provided by the Serval Stack. It offers functionality such as a server, a client or general utilities when implementing a CoAP based application. This ensures that any message sent and received will be a CoAP message and treated as such.

![](/files/-Lj1NZM-SyQPzKVZnhRt)

Client Functionality

| Function                            | Description                                                                                                                                                                                                                                                                                                         |
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `CoapServer_initialize()`           | This function is called to initialize the CoAP client (and server) and related modules. It must be called before any other CoAP-Client related function.                                                                                                                                                            |
| `CoapServer_startInstance()`        | This function is called to start the CoAP client (and server). As input it receives a port, to which the server will listen, and a reference to a callbackfunction, which will be called every time the server receives a message.                                                                                  |
| `CoapClient_initialize()`           | If it is desired to use different UDP sockets for server and client, this function must be called for the client instead of CoapServer\_initialize. This function initializes only the client and relevant modules. Per default, this function is disabled.                                                         |
| `CoapClient_startInstance()`        | This function is called to start the CoAP client after the client has been initialized using CoapClient\_initialize. Per default, this function is disabled, if CoapClient\_initialize is disabled, as well.                                                                                                        |
| `CoapClient_request()`              | This function is called to send a message as a request. As input, it receives a message, a callback for informing about the status of sending and a callback to handle a response to this message.                                                                                                                  |
| `CoapClient_initReqMsg()`           | This function is called to initialize a message. As input, it receives the target’s IP address, its port and the pointer to a message.                                                                                                                                                                              |
| Utility                             |                                                                                                                                                                                                                                                                                                                     |
| `CoapParser_setup()`                | This function sets up a CoAP-Parser which will be used to receive certain information from a CoAP-Message, such as the code, the payload or the options. As input, it receives a variable of type CoapParser\_T and the pointer to a message.                                                                       |
| `CoapParser_getCode()`              | This function is called to receive the code of a message. As input, it receives a pointer to a message.                                                                                                                                                                                                             |
| `CoapParser_getPayload()`           | This function is called to receive the payload of a message. As input, it receives a pointer to the previously set up parser, a pointer to a payload array, and the array’s length.                                                                                                                                 |
| `CoapSerializer_setup()`            | This function sets up a CoAP-Serializer, which will be used to create a message. It handles setting options, the payload, the code, etc, for a given message. As input, it receives variable of type CoapSerializer\_T, the pointer to a message, and a code indicating whether a RESPONSE or a REQUEST is created. |
| `CoapSerializer_setCode()`          | This function is called to set the code of a message. As input, it receives the serializer, a message and the code to be set.                                                                                                                                                                                       |
| `CoapSerializer_serializePayload()` | This function is called to set the payload for a message. As input, it receives the serializer, a message pointer, the payload and the payload’s length                                                                                                                                                             |


---

# Agent Instructions: 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:

```
GET https://alfredo-reyes-montero.gitbook.io/iot-bosch/devices/bosch-xdk-110/protocols/coap/overview.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
