# CoAP

# CoAP

This module includes functions that control CoAP communication.

## Summary

The functions in this module are available when CoAP API feature (`OPENTHREAD_CONFIG_COAP_API_ENABLE`) is enabled.

| ### Enumerations ||
|---|---|
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gaac92cebc73df7f7b25cf5e7357d35355` | enumCoAP Block Size Exponents. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga9aa05cbbcfa6954cb13e4745b8cec424{ https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424ac4ce1a030d672d10377cb1025738cfb5 = (((( 0 ) & 0x7) << 5) | (( 0 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424ace571b160fc9d1b3e081637a3a3fc68b = (((( 0 ) & 0x7) << 5) | (( 1 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424afad04665c0d0f8d2c24b5d9b1b6c71f4 = (((( 0 ) & 0x7) << 5) | (( 2 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424a8b6f08c891c24be7b614abadd1783c15 = (((( 0 ) & 0x7) << 5) | (( 3 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424a7383f09cbc95352434fee54dc7678ffe = (((( 0 ) & 0x7) << 5) | (( 4 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424ad79a0b6e1364a6720a261cfd14feb578 = (((( 2 ) & 0x7) << 5) | (( 0 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424a6e453bed20eb0ada748c76db2f5b1993 = (((( 2 ) & 0x7) << 5) | (( 1 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424aac66e6f3a95b0ea90ff71e079bfe4d00 = (((( 2 ) & 0x7) << 5) | (( 2 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424ae25a4a9fb3e692b56351b6b4b9eab77f = (((( 2 ) & 0x7) << 5) | (( 3 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424a64f3c4110b8b382da4ed14d8c00c67e0 = (((( 2 ) & 0x7) << 5) | (( 4 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424ae8b4f9157d6e3be4ba91ed4cafcc29e7 = (((( 2 ) & 0x7) << 5) | (( 5 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424a92a781fb62f234cdafcd00638c56fd9c = (((( 2 ) & 0x7) << 5) | (( 31 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424adf2177adbe241aeb9c024ca2ab86c3e7 = (((( 4 ) & 0x7) << 5) | (( 0 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424a41c9ed06fc0ef2eef3b7b0ba509f608e = (((( 4 ) & 0x7) << 5) | (( 1 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424a034761acd8f16d04107e3b67903a4065 = (((( 4 ) & 0x7) << 5) | (( 2 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424a2554d186a9fd6c68a9066cb531e67977 = (((( 4 ) & 0x7) << 5) | (( 3 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424a19f3a69961e353f808dfe7316e300887 = (((( 4 ) & 0x7) << 5) | (( 4 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424a34c8b9fc58617c334c22211c7bbca7b6 = (((( 4 ) & 0x7) << 5) | (( 5 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424ae929b326b77582cce737a0e6f0b5f10d = (((( 4 ) & 0x7) << 5) | (( 6 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424a65ea05d2c9e4c1b648e479f2d0de6a84 = (((( 4 ) & 0x7) << 5) | (( 8 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424a7af696aeeff0b1e32aa842d71e1008af = (((( 4 ) & 0x7) << 5) | (( 12 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424a24155f58e055a01685bd42a045bab7eb = (((( 4 ) & 0x7) << 5) | (( 13 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424ae085e6d23ccca6cc5fb193526b6a9cb6 = (((( 4 ) & 0x7) << 5) | (( 15 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424aa8d155f1343cb44b0cc0956d2c8a27c2 = (((( 5 ) & 0x7) << 5) | (( 0 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424a29ec2bfbfbde82fbf6895433b83a890b = (((( 5 ) & 0x7) << 5) | (( 1 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424abda59987a56928e0d24859c7996052a3 = (((( 5 ) & 0x7) << 5) | (( 2 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424a76aaab5c37777a2ee769dadb6bb1d6ad = (((( 5 ) & 0x7) << 5) | (( 3 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424a1352f8685d01a7e35b00dcebdefee34b = (((( 5 ) & 0x7) << 5) | (( 4 ) & 0x1f)), https://openthread.io/reference/group/api-coap#group__api-coap_1gga9aa05cbbcfa6954cb13e4745b8cec424a5ac77a07127f83ea4dfa4fb5580f585c = (((( 5 ) & 0x7) << 5) | (( 5 ) & 0x1f)) }` | enumCoAP Code values. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga0f76047fc3d614ee331e8fa0fbce4c1d{ https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1dab7f1128e726d8c2ca5235562d64d8a17 = 0, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1da3ab878c8d9f0bd8b89cee3f37864f2af = 16, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1da3bc40ac29a1969260a10a8f2920edae5 = 17, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1da43044e611c8002028a27d7dcb171b2fd = 18, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1da679046dd227fa77adaabcdb1a93c879c = 40, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1dace8b3a993fc147d59e52b67b9e9e8a11 = 41, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1da87f7984fde21979e96543137923fdc46 = 42, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1dae755e1752c421da0468843da93ffb9b8 = 47, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1da4112a45184d5dec831bedb536e78f6f9 = 50, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1da45a9f079ed788dc6b0e797422600dcab = 51, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1dac382ec38d64786dbf2591362e47bc7fb = 52, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1daeb23d0a16025e94a5048c75338bc9495 = 60, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1da89a77604c7cd72939ac9808a865d40d3 = 61, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1da45912e0636cc25420a966585d9cbeeae = 96, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1da50500f5b4d6b7fd3a336e6dee93b06d2 = 97, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1daeb95ea18b0ec63c371627d02ba1409d9 = 98, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1da1c01e0d37f97a19c914f1c1e49396798 = 101, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1dadeaaaaf46f92b37abc186d4e5b115986 = 102, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1dae945371b93c167070a8203c06d07649c = 110, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1dabd8cb8d761c373eb28f2c1a47eb1d9c1 = 111, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1daaf8d5b01b7ed8863e8589637a23ba555 = 112, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1dac3f777bfa898924339d878f687cc1999 = 113, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1da68fe3742ebfab4bd59a997c8f88f45b2 = 114, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1daa0d162417648b306de8e2c3f0f6fd667 = 115, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1da717bc4f64706093c1b01d86c8b6fcb90 = 256, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1dad8cb09a1bbe51030f791dc8c2f8e7062 = 310, https://openthread.io/reference/group/api-coap#group__api-coap_1gga0f76047fc3d614ee331e8fa0fbce4c1daf1ff125833cb92fb20454edc91c2d36f = 311 }` | enumCoAP Content Format codes. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gaf99e791d0ec85184953d11f33fcdc8fd{ https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fdafeb5d391097ba7776f13c7da3682de89 = 1, https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fda184cab3264de335ad011013490a68d55 = 3, https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fda4eaf6dee42e4ddfb20194d9836c8f752 = 4, https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fda23171b8fb823f95f14879e6c76435644 = 5, https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fda7985fe2237361e702c179e68ea77788e = 6, https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fda9801fa17770c7e4d06c1c52dfad5e0bb = 7, https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fda0a333d9918866e9dbc6bad5db3e2d07f = 8, https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fda62504f1baa467d9158db715540890276 = 11, https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fda2fa9293108d5aa33549a720e1100adfe = 12, https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fdadc16321d14d3c6007c5c60faae16a722 = 14, https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fda01c5a3dd4dedf5c54443a283b08e85ab = 15, https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fda18a14f1aa3d248e48fbe0bbb7d3016a3 = 17, https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fda020b97b499651ea75549af7978eef17f = 20, https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fdaf3cb11ac6932c4ac8b7d7f847302c930 = 23, https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fda6b69b18aa0558f24888598b7e1673b2c = 27, https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fda9e2e203d52eb273229ce9dbe7a5bcb30 = 28, https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fda70c3f146a266615a18cf15bdc1a3e065 = 35, https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fdac4d5fb1098e5a82cbaac74512dbf20a0 = 39, https://openthread.io/reference/group/api-coap#group__api-coap_1ggaf99e791d0ec85184953d11f33fcdc8fda04fcb12384f08624291e449afbb12e70 = 60 }` | enumCoAP Option Numbers. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga33033483fa0eeb32532d9034cfafe97c{ https://openthread.io/reference/group/api-coap#group__api-coap_1gga33033483fa0eeb32532d9034cfafe97ca29cc5907e1ac23641cd98f9b5777f321 = 0, https://openthread.io/reference/group/api-coap#group__api-coap_1gga33033483fa0eeb32532d9034cfafe97ca7609071c0d0a7cef24fb65028b7fdf8c = 1, https://openthread.io/reference/group/api-coap#group__api-coap_1gga33033483fa0eeb32532d9034cfafe97ca2db7dc49eb39b23bfe5a582ea18b151b = 2, https://openthread.io/reference/group/api-coap#group__api-coap_1gga33033483fa0eeb32532d9034cfafe97ca5b51a7391d4dfaa50f18ecb2c5cf2979 = 3 }` | enumCoAP Type values (2 bit unsigned integer). |

| ### Typedefs ||
|---|---|
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga49e229d81b0c7dd32b0fd1925736c048` | typedef `enum https://openthread.io/reference/group/api-coap#group__api-coap_1gaac92cebc73df7f7b25cf5e7357d35355` CoAP Block Size Exponents. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga0c640fe414553134e76899bad13e7242)(void *aContext, const uint8_t *aBlock, uint32_t aPosition, uint16_t aBlockLength, bool aMore, uint32_t aTotalLength)` | typedef `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49(*` Pointer is called when a CoAP message with a block-wise transfer option is received. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gac95ce5575d9ef5d849587cb6ee0975cd` | typedef `struct https://openthread.io/reference/struct/ot-coap-blockwise-resource` Represents a CoAP resource with block-wise transfer. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gaff785a9a39107f9447d5c183ab04aa6a)(void *aContext, uint8_t *aBlock, uint32_t aPosition, uint16_t *aBlockLength, bool *aMore)` | typedef `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49(*` Pointer is called before the next block in a block-wise transfer is sent. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gaf2ea1a3bef8e32995d8c812ef6198095` | typedef `enum https://openthread.io/reference/group/api-coap#group__api-coap_1ga9aa05cbbcfa6954cb13e4745b8cec424` CoAP Code values. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga32e1115b8e6282e3af5e894f67216934` | typedef `struct https://openthread.io/reference/struct/ot-coap-option` Represents a CoAP option. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga04ecbfe1b4b95d3506f8da9c5a1cf0c9` | typedef `enum https://openthread.io/reference/group/api-coap#group__api-coap_1ga0f76047fc3d614ee331e8fa0fbce4c1d` CoAP Content Format codes. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gab471a3c94518ff59d944d4e0d39a0241` | typedef `struct https://openthread.io/reference/struct/ot-coap-option-iterator` Acts as an iterator for CoAP options. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gaeaa0dfabf9691e26eed4fd1d847cd599` | typedef `enum https://openthread.io/reference/group/api-coap#group__api-coap_1gaf99e791d0ec85184953d11f33fcdc8fd` CoAP Option Numbers. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga43485a1c168a672b36d35f4c6259dbea)(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)` | typedef `void(*` Pointer is called when a CoAP request with a given Uri-Path is received. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga4e57867951c7a3dae87c1eaa1144c984` | typedef `struct https://openthread.io/reference/struct/ot-coap-resource` Represents a CoAP resource. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gafc803a628b45505ae897bf4a72d70b92)(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)` | typedef `bool(*` Pointer is called as a fallback if a response did not match a stored CoAP request. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga42fc3fdfc2f3dacf34041b5ee4a9c6eb)(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo, otError aResult)` | typedef `void(*` Pointer is called when a CoAP response is received or on the request timeout. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga09c16e0098a1e017aac6cefdb13dc797` | typedef `struct https://openthread.io/reference/struct/ot-coap-token` Represents a CoAP message token. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga1da204060b4dbaee79a6a3f49ed98f3a` | typedef `struct https://openthread.io/reference/struct/ot-coap-tx-parameters` Represents the CoAP transmission parameters. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gab0bdf6072b4897a2fb4a11d13e78aebd` | typedef `enum https://openthread.io/reference/group/api-coap#group__api-coap_1ga33033483fa0eeb32532d9034cfafe97c` CoAP Type values (2 bit unsigned integer). |

| ### Functions ||
|---|---|
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga5e5f1fca47e4aaee4c69980d1634b92e(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/struct/ot-coap-blockwise-resource *aResource)` | `void` Adds a block-wise resource to the CoAP server. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga471a523886a4939948ccbf2d7e974a90(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/struct/ot-coap-resource *aResource)` | `void` Adds a resource to the CoAP server. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga9d1aed335017239314cc9d49e1fb8183(https://openthread.io/reference/group/api-coap#group__api-coap_1gaac92cebc73df7f7b25cf5e7357d35355 aSize)` | `uint16_t` Converts a CoAP Block option SZX field to the actual block size. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga2fe14a95cafcdae713bfda79f8223d14(https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, uint32_t aNum, bool aMore, https://openthread.io/reference/group/api-coap#group__api-coap_1gaac92cebc73df7f7b25cf5e7357d35355 aSize)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Appends a Block1 option. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gad77f2eaa7902dd11fe32cfa7db788bbd(https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, uint32_t aNum, bool aMore, https://openthread.io/reference/group/api-coap#group__api-coap_1gaac92cebc73df7f7b25cf5e7357d35355 aSize)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Appends a Block2 option. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga03f9f5f7564ebf2fd9d8fba77524f76e(https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, https://openthread.io/reference/group/api-coap#group__api-coap_1ga0f76047fc3d614ee331e8fa0fbce4c1d aContentFormat)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Appends the Content Format CoAP option as specified in <https://tools.ietf.org/html/rfc7252#page-92>. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga22beb6a4c787877032256d93f322f543(https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, uint32_t aMaxAge)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Appends a Max-Age option. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga0b4ec5ec8d715161b2cf56c5dc5e203a(https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, uint32_t aObserve)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Appends an Observe option. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga01e9c1c5df1bd934a48fcc4620d8cab3(https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, uint16_t aNumber, uint16_t aLength, const void *aValue)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Appends a CoAP option in a header. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gae580dca4ab973d672ac1136a9d6202de(https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, const char *aUriPath)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Appends a Proxy-Uri option. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga39c26403482aa325e260fca09ef4967d(https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, uint16_t aNumber, uint32_t aValue)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Appends an unsigned integer CoAP option as specified in <https://tools.ietf.org/html/rfc7252#section-3.2>. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga54476846ba5d6b60d69793c8e5c3fc8b(https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, const char *aUriPath)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Appends a Uri-Path option. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga0f6384e234a7e6bb288da38e3f22a5aa(https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, const char *aUriQuery)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Appends a single Uri-Query option. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga6da5ce93b7fed475669ef06b7a9da16b(https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, const char *aUriQuery)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Appends a Uri-Query option. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gaa09a8cc14587a43448b727e263bcfbf4(const https://openthread.io/reference/struct/ot-coap-token *aFirstToken, const https://openthread.io/reference/struct/ot-coap-token *aSecondToken)` | `bool` Indicates whether two given CoAP Tokens are equal. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gaaabd24a74cc9f2246f554751929b6f9e(const https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage)` | `const char *` Returns the CoAP Code as human readable string. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga49e2d621f10299d7371126d9bcd738fc(https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, uint8_t aTokenLength)` | `void` Writes a randomly generated Token of a given length in the CoAP message. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga3409906bfca8d831ab9859ce52ca1f1a(const https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage)` | `https://openthread.io/reference/group/api-coap#group__api-coap_1ga9aa05cbbcfa6954cb13e4745b8cec424` Returns the Code value. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga91fc6eeffe682e9d936d1ad6c949b940(const https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage)` | `uint16_t` Returns the Message ID value. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga58eec8c46e5a7c64ca3585d66f60f6c3(const https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage)` | `const uint8_t *` **[Deprecated.](https://openthread.io/reference/deprecated/deprecated)** This function is deprecated. Use `https://openthread.io/reference/group/api-coap#group__api-coap_1gaffe4877b326ea8a1de335eb5a7b49928` instead.Returns a pointer to the Token value. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga8b9cc67c583b31ba0b76debce604eafb(const https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage)` | `uint8_t` **[Deprecated.](https://openthread.io/reference/deprecated/deprecated)** This function is deprecated. Use `https://openthread.io/reference/group/api-coap#group__api-coap_1gaffe4877b326ea8a1de335eb5a7b49928` instead.Returns the Token length. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga9233718bec8ca0e7beb06afdce841cd3(const https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage)` | `https://openthread.io/reference/group/api-coap#group__api-coap_1ga33033483fa0eeb32532d9034cfafe97c` Returns the Type value. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga7098239d82616643f664a04bc17aa509(https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, https://openthread.io/reference/group/api-coap#group__api-coap_1ga33033483fa0eeb32532d9034cfafe97c aType, https://openthread.io/reference/group/api-coap#group__api-coap_1ga9aa05cbbcfa6954cb13e4745b8cec424 aCode)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Initializes a CoAP message. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gaa99288ae466e8a1d60cbef31b074ffe9(https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aResponse, const https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aRequest, https://openthread.io/reference/group/api-coap#group__api-coap_1ga33033483fa0eeb32532d9034cfafe97c aType, https://openthread.io/reference/group/api-coap#group__api-coap_1ga9aa05cbbcfa6954cb13e4745b8cec424 aCode)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Initializes a CoAP message as a response to a request. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gaffe4877b326ea8a1de335eb5a7b49928(const https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, https://openthread.io/reference/struct/ot-coap-token *aToken)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Reads the Token from the CoAP message. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga296b1ebc66a062ae3b48256934cdaa1f(https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, https://openthread.io/reference/group/api-coap#group__api-coap_1ga9aa05cbbcfa6954cb13e4745b8cec424 aCode)` | `void` Sets the Code value. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gaa2785c25f0574da5e8bf11f9f5035055(https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Adds Payload Marker indicating beginning of the payload to the CoAP header. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga1eb3040373e464254fb59fa14909b0b8(https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, const uint8_t *aToken, uint8_t aTokenLength)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` **[Deprecated.](https://openthread.io/reference/deprecated/deprecated)** This function is deprecated. Use `https://openthread.io/reference/group/api-coap#group__api-coap_1ga116ebe406acb72f618e56b1ec5a607ef` instead.Sets the Token value and length in a CoAP message. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga116ebe406acb72f618e56b1ec5a607ef(https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, const https://openthread.io/reference/struct/ot-coap-token *aToken)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Writes the Token in the CoAP message. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga448efdbadf8a2102e9d22f1f8dddde1f(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, const https://openthread.io/reference/struct/ot-message-settings *aSettings)` | `https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *` Creates a new CoAP message. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga8d35cbc582f8475e25428ff7b2ec8bba(https://openthread.io/reference/struct/ot-coap-option-iterator *aIterator)` | `const https://openthread.io/reference/struct/ot-coap-option *` Returns a pointer to the first option. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gac3da438598595fcc17b205bf439a9007(https://openthread.io/reference/struct/ot-coap-option-iterator *aIterator, uint16_t aOption)` | `const https://openthread.io/reference/struct/ot-coap-option *` Returns a pointer to the first option matching the specified option number. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gaeabfe5bc812c49ee938c468d744a4a78(https://openthread.io/reference/struct/ot-coap-option-iterator *aIterator)` | `const https://openthread.io/reference/struct/ot-coap-option *` Returns a pointer to the next option. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gad56f93dfa46300bac5c07ce67e2c1d81(https://openthread.io/reference/struct/ot-coap-option-iterator *aIterator, uint16_t aOption)` | `const https://openthread.io/reference/struct/ot-coap-option *` Returns a pointer to the next option matching the specified option number. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga868c44b97725e9858f3e1d919058d44b(https://openthread.io/reference/struct/ot-coap-option-iterator *aIterator, uint64_t *aValue)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Fills current option value into `aValue` assuming the current value is an unsigned integer encoded according to <https://tools.ietf.org/html/rfc7252#section-3.2>. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gaeabd92e03c3e2a3254ba7b2b60da843a(https://openthread.io/reference/struct/ot-coap-option-iterator *aIterator, void *aValue)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Fills current option value into `aValue`. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga825bf7ca5eaf11cf48e31b3073630c8e(https://openthread.io/reference/struct/ot-coap-option-iterator *aIterator, const https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Initializes an iterator for the options in the given message. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga0667022aac8f0e8c3babd04383ef58e1(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/struct/ot-coap-blockwise-resource *aResource)` | `void` Removes a block-wise resource from the CoAP server. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga3a7b99c48bdad5ed0a970e118ac54a6a(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/struct/ot-coap-resource *aResource)` | `void` Removes a resource from the CoAP server. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gaa2adc6e767444a6b2323c09e0970d6e0(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, const https://openthread.io/reference/struct/ot-message-info *aMessageInfo, https://openthread.io/reference/group/api-coap#group__api-coap_1ga42fc3fdfc2f3dacf34041b5ee4a9c6eb aHandler, void *aContext)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Sends a CoAP request. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gaff1d7b5a27f3fbb5e1274b8f5d1ae23a(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, const https://openthread.io/reference/struct/ot-message-info *aMessageInfo, https://openthread.io/reference/group/api-coap#group__api-coap_1ga42fc3fdfc2f3dacf34041b5ee4a9c6eb aHandler, void *aContext, https://openthread.io/reference/group/api-coap#group__api-coap_1gaff785a9a39107f9447d5c183ab04aa6a aTransmitHook, https://openthread.io/reference/group/api-coap#group__api-coap_1ga0c640fe414553134e76899bad13e7242 aReceiveHook)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Sends a CoAP request block-wise. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga99fd2081841181d67eaa93e9e189f7ab(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, const https://openthread.io/reference/struct/ot-message-info *aMessageInfo, https://openthread.io/reference/group/api-coap#group__api-coap_1ga42fc3fdfc2f3dacf34041b5ee4a9c6eb aHandler, void *aContext, const https://openthread.io/reference/struct/ot-coap-tx-parameters *aTxParameters, https://openthread.io/reference/group/api-coap#group__api-coap_1gaff785a9a39107f9447d5c183ab04aa6a aTransmitHook, https://openthread.io/reference/group/api-coap#group__api-coap_1ga0c640fe414553134e76899bad13e7242 aReceiveHook)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Sends a CoAP request block-wise with custom transmission parameters. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gace3de6a217f540d8fe26bbf7834400e3(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, const https://openthread.io/reference/struct/ot-message-info *aMessageInfo, https://openthread.io/reference/group/api-coap#group__api-coap_1ga42fc3fdfc2f3dacf34041b5ee4a9c6eb aHandler, void *aContext, const https://openthread.io/reference/struct/ot-coap-tx-parameters *aTxParameters)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Sends a CoAP request with custom transmission parameters. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gac0dbb2f439339174904600312643dfb6(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, const https://openthread.io/reference/struct/ot-message-info *aMessageInfo)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Sends a CoAP response from the server. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga18601bfc7f5b3c1c9d65e623e5fa4c7e(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, const https://openthread.io/reference/struct/ot-message-info *aMessageInfo, void *aContext, https://openthread.io/reference/group/api-coap#group__api-coap_1gaff785a9a39107f9447d5c183ab04aa6a aTransmitHook)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Sends a CoAP response block-wise from the server. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga1c9cd4ff2b1b35551441ed358ab5870b(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, const https://openthread.io/reference/struct/ot-message-info *aMessageInfo, const https://openthread.io/reference/struct/ot-coap-tx-parameters *aTxParameters, void *aContext, https://openthread.io/reference/group/api-coap#group__api-coap_1gaff785a9a39107f9447d5c183ab04aa6a aTransmitHook)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Sends a CoAP response block-wise from the server with custom transmission parameters. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gabb5d409c04bdbdef34683ad503e489b0(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, const https://openthread.io/reference/struct/ot-message-info *aMessageInfo, const https://openthread.io/reference/struct/ot-coap-tx-parameters *aTxParameters)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Sends a CoAP response from the server with custom transmission parameters. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga5c815c917f61e1351e83e02e1266decd(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/group/api-coap#group__api-coap_1ga43485a1c168a672b36d35f4c6259dbea aHandler, void *aContext)` | `void` Sets the default handler for unhandled CoAP requests. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gac5cef4bf79694b2c8b554f645e73cf8e(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/group/api-coap#group__api-coap_1gafc803a628b45505ae897bf4a72d70b92 aHandler, void *aContext)` | `void` Sets a fallback handler for CoAP responses not matching any active/pending request. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1gaf1d39534c0c1ac4acf6af151dbd5788e(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, uint16_t aPort)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Starts the CoAP server. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga63f53a430194cc0ed60cb7687a779a1e(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Stops the CoAP server. |

| ### Macros ||
|---|---|
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga694906957ede9cfeed96e82d935c3f00 ((((c) & 0x7) << 5) | ((d) & 0x1f))` | Helper macro to define CoAP Code values. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga2048b522c1e092ed661c3e1dccf952f1 2` | Default token length. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga574d3b0d03530da764ae614b9dae3a8a 20` | Max retransmit supported by OpenThread. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga6ba989a775c21f80a8a98a5bd465af00 8` | Max token length as specified (RFC 7252). |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga2d81904d278adb43064415ada83a75a5 1000` | Minimal ACK timeout in milliseconds supported by OpenThread. |
| `https://openthread.io/reference/group/api-coap#group__api-coap_1ga532f66cc82928d67f8a77eb6f0f0dee8 5683` | Default CoAP port, as specified in RFC 7252. |

| ### Structs ||
|---|---|
| [otCoapBlockwiseResource](https://openthread.io/reference/struct/ot-coap-blockwise-resource) | Represents a CoAP resource with block-wise transfer. |
| [otCoapOption](https://openthread.io/reference/struct/ot-coap-option) | Represents a CoAP option. |
| [otCoapOptionIterator](https://openthread.io/reference/struct/ot-coap-option-iterator) | Acts as an iterator for CoAP options. |
| [otCoapResource](https://openthread.io/reference/struct/ot-coap-resource) | Represents a CoAP resource. |
| [otCoapToken](https://openthread.io/reference/struct/ot-coap-token) | Represents a CoAP message token. |
| [otCoapTxParameters](https://openthread.io/reference/struct/ot-coap-tx-parameters) | Represents the CoAP transmission parameters. |

## Enumerations

### otCoapBlockSzx

```
 otCoapBlockSzx
```
CoAP Block Size Exponents.

### otCoapCode

```
 otCoapCode
```
CoAP Code values.

| Properties ||
|---|---|
| `OT_COAP_CODE_BAD_GATEWAY` | Bad Gateway. |
| `OT_COAP_CODE_BAD_OPTION` | Bad Option. |
| `OT_COAP_CODE_BAD_REQUEST` | Bad Request. |
| `OT_COAP_CODE_CHANGED` | Changed. |
| `OT_COAP_CODE_CONTENT` | Content. |
| `OT_COAP_CODE_CONTINUE` | RFC7959 Continue. |
| `OT_COAP_CODE_CREATED` | Created. |
| `OT_COAP_CODE_DELETE` | Delete. |
| `OT_COAP_CODE_DELETED` | Deleted. |
| `OT_COAP_CODE_EMPTY` | Empty message code. |
| `OT_COAP_CODE_FORBIDDEN` | Forbidden. |
| `OT_COAP_CODE_GATEWAY_TIMEOUT` | Gateway Timeout. |
| `OT_COAP_CODE_GET` | Get. |
| `OT_COAP_CODE_INTERNAL_ERROR` | Internal Server Error. |
| `OT_COAP_CODE_METHOD_NOT_ALLOWED` | Method Not Allowed. |
| `OT_COAP_CODE_NOT_ACCEPTABLE` | Not Acceptable. |
| `OT_COAP_CODE_NOT_FOUND` | Not Found. |
| `OT_COAP_CODE_NOT_IMPLEMENTED` | Not Implemented. |
| `OT_COAP_CODE_POST` | Post. |
| `OT_COAP_CODE_PRECONDITION_FAILED` | Precondition Failed. |
| `OT_COAP_CODE_PROXY_NOT_SUPPORTED` | Proxying Not Supported. |
| `OT_COAP_CODE_PUT` | Put. |
| `OT_COAP_CODE_REQUEST_INCOMPLETE` | RFC7959 Request Entity Incomplete. |
| `OT_COAP_CODE_REQUEST_TOO_LARGE` | Request Entity Too Large. |
| `OT_COAP_CODE_RESPONSE_MIN` | 2.00 |
| `OT_COAP_CODE_SERVICE_UNAVAILABLE` | Service Unavailable. |
| `OT_COAP_CODE_UNAUTHORIZED` | Unauthorized. |
| `OT_COAP_CODE_UNSUPPORTED_FORMAT` | Unsupported Content-Format. |
| `OT_COAP_CODE_VALID` | Valid. |

### otCoapOptionContentFormat

```
 otCoapOptionContentFormat
```
CoAP Content Format codes.

The full list is documented at <https://www.iana.org/assignments/core-parameters/core-parameters.xhtml#content-formats>

| Properties ||
|---|---|
| `OT_COAP_OPTION_CONTENT_FORMAT_CBOR` | application/cbor: \[RFC7049\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_COAP_GROUP_JSON` | application/coap-group+json: \[RFC7390\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_COSE_ENCRYPT` | application/cose; cose-type="cose-encrypt": \[RFC8152\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_COSE_ENCRYPT0` | application/cose; cose-type="cose-encrypt0": \[RFC8152\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_COSE_KEY` | application/cose-key: \[RFC8152\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_COSE_KEY_SET` | application/cose-key-set: \[RFC8152\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_COSE_MAC` | application/cose; cose-type="cose-mac": \[RFC8152\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_COSE_MAC0` | application/cose; cose-type="cose-mac0": \[RFC8152\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_COSE_SIGN` | application/cose; cose-type="cose-sign": \[RFC8152\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_COSE_SIGN1` | application/cose; cose-type="cose-sign1": \[RFC8152\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_CWT` | application/cwt: \[RFC8392\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_EXI` | application/exi: \["Efficient XML Interchange (EXI)"\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_JSON` | application/json: \[RFC7159\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_JSON_PATCH_JSON` | application/json-patch+json: \[RFC6902\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_LINK_FORMAT` | application/link-format: \[RFC6690\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_MERGE_PATCH_JSON` | application/merge-patch+json: \[RFC7396\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_OCTET_STREAM` | application/octet-stream: \[RFC2045\]\[RFC2046\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_SENML_CBOR` | application/senml+cbor: \[RFC8428\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_SENML_EXI` | application/senml-exi: \[RFC8428\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_SENML_JSON` | application/senml+json: \[RFC8428\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_SENML_XML` | application/senml+xml: \[RFC8428\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_SENSML_CBOR` | application/sensml+cbor: \[RFC8428\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_SENSML_EXI` | application/sensml-exi: \[RFC8428\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_SENSML_JSON` | application/sensml+json: \[RFC8428\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_SENSML_XML` | application/sensml+xml: \[RFC8428\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_TEXT_PLAIN` | txt/plain; charset=utf-8: \[RFC2046\]\[RFC3676\]\[RFC5147\] |
| `OT_COAP_OPTION_CONTENT_FORMAT_XML` | application/xml: \[RFC3023\] |

### otCoapOptionType

```
 otCoapOptionType
```
CoAP Option Numbers.

| Properties ||
|---|---|
| `OT_COAP_OPTION_ACCEPT` | Accept. |
| `OT_COAP_OPTION_BLOCK1` | Block1 (RFC7959) |
| `OT_COAP_OPTION_BLOCK2` | Block2 (RFC7959) |
| `OT_COAP_OPTION_CONTENT_FORMAT` | Content-Format. |
| `OT_COAP_OPTION_E_TAG` | ETag. |
| `OT_COAP_OPTION_IF_MATCH` | If-Match. |
| `OT_COAP_OPTION_IF_NONE_MATCH` | If-None-Match. |
| `OT_COAP_OPTION_LOCATION_PATH` | Location-Path. |
| `OT_COAP_OPTION_LOCATION_QUERY` | Location-Query. |
| `OT_COAP_OPTION_MAX_AGE` | Max-Age. |
| `OT_COAP_OPTION_OBSERVE` | Observe \[RFC7641\]. |
| `OT_COAP_OPTION_PROXY_SCHEME` | Proxy-Scheme. |
| `OT_COAP_OPTION_PROXY_URI` | Proxy-Uri. |
| `OT_COAP_OPTION_SIZE1` | Size1. |
| `OT_COAP_OPTION_SIZE2` | Size2 (RFC7959) |
| `OT_COAP_OPTION_URI_HOST` | Uri-Host. |
| `OT_COAP_OPTION_URI_PATH` | Uri-Path. |
| `OT_COAP_OPTION_URI_PORT` | Uri-Port. |
| `OT_COAP_OPTION_URI_QUERY` | Uri-Query. |

### otCoapType

```
 otCoapType
```
CoAP Type values (2 bit unsigned integer).

| Properties ||
|---|---|
| `OT_COAP_TYPE_ACKNOWLEDGMENT` | Acknowledgment. |
| `OT_COAP_TYPE_CONFIRMABLE` | Confirmable. |
| `OT_COAP_TYPE_NON_CONFIRMABLE` | Non-confirmable. |
| `OT_COAP_TYPE_RESET` | Reset. |

## Typedefs

### otCoapBlockSzx

```
enum otCoapBlockSzx otCoapBlockSzx
```
CoAP Block Size Exponents.

### otCoapBlockwiseReceiveHook

```
otError(* otCoapBlockwiseReceiveHook)(void *aContext, const uint8_t *aBlock, uint32_t aPosition, uint16_t aBlockLength, bool aMore, uint32_t aTotalLength)
```
Pointer is called when a CoAP message with a block-wise transfer option is received.

Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aContext` | A pointer to application-specific context. | | `[in] aBlock` | A pointer to the block segment. | | `[in] aPosition` | The position of `aBlock` in a sequence in bytes. | | `[in] aBlockLength` | The length of the block segment in bytes. | | `[in] aMore` | Flag if more block segments are following. | | `[in] aTotalLength` | The total length in bytes of the transferred information (indicated by a Size1 or Size2 option). | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Block segment was stored successfully. | | `OT_ERROR_NO_BUFS` | No more memory to store blocks. | | `OT_ERROR_NO_FRAME_RECEIVED` | Block segment missing. | |

### otCoapBlockwiseResource

```
struct otCoapBlockwiseResource otCoapBlockwiseResource
```
Represents a CoAP resource with block-wise transfer.

### otCoapBlockwiseTransmitHook

```
otError(* otCoapBlockwiseTransmitHook)(void *aContext, uint8_t *aBlock, uint32_t aPosition, uint16_t *aBlockLength, bool *aMore)
```
Pointer is called before the next block in a block-wise transfer is sent.

Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.

By changing the value of aBlockLength, the block size of the whole exchange is renegotiated. It is recommended to do this after the first block has been received as later changes could cause problems with other CoAP implementations.

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aContext` | A pointer to application-specific context. | | `[in,out] aBlock` | A pointer to where the block segment can be written to. | | `[in] aPosition` | The position in a sequence from which to obtain the block segment. | | `[in,out] aBlockLength` | On entry, the maximum block segment length in bytes. | | `[out] aMore` | A pointer to the flag if more block segments will follow. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | No error occurred. | | `OT_ERROR_INVALID_ARGS` | Block at `aPosition` does not exist. | |

### otCoapCode

```
enum otCoapCode otCoapCode
```
CoAP Code values.

### otCoapOption

```
struct otCoapOption otCoapOption
```
Represents a CoAP option.

### otCoapOptionContentFormat

```
enum otCoapOptionContentFormat otCoapOptionContentFormat
```
CoAP Content Format codes.

The full list is documented at <https://www.iana.org/assignments/core-parameters/core-parameters.xhtml#content-formats>

### otCoapOptionIterator

```
struct otCoapOptionIterator otCoapOptionIterator
```
Acts as an iterator for CoAP options.

### otCoapOptionType

```
enum otCoapOptionType otCoapOptionType
```
CoAP Option Numbers.

### otCoapRequestHandler

```
void(* otCoapRequestHandler)(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
```
Pointer is called when a CoAP request with a given Uri-Path is received.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aContext` | A pointer to arbitrary context information. | | `[in] aMessage` | A pointer to the message. | | `[in] aMessageInfo` | A pointer to the message info for `aMessage`. | |

### otCoapResource

```
struct otCoapResource otCoapResource
```
Represents a CoAP resource.

### otCoapResponseFallback

```
bool(* otCoapResponseFallback)(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
```
Pointer is called as a fallback if a response did not match a stored CoAP request.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aContext` | A pointer to arbitrary context information. | | `[in] aMessage` | A pointer to the message. | | `[in] aMessageInfo` | A pointer to the message info for `aMessage`. | |
| Return Values | |---|---| | `TRUE` | The fallback handled the response. | | `FALSE` | OpenThread takes default actions for response. | |

### otCoapResponseHandler

```
void(* otCoapResponseHandler)(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo, otError aResult)
```
Pointer is called when a CoAP response is received or on the request timeout.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aContext` | A pointer to application-specific context. | | `[in] aMessage` | A pointer to the message buffer containing the response. NULL if no response was received. | | `[in] aMessageInfo` | A pointer to the message info for `aMessage`. NULL if no response was received. | | `[in] aResult` | A result of the CoAP transaction. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | A response was received successfully. | | `OT_ERROR_ABORT` | A CoAP transaction was reset by peer. | | `OT_ERROR_RESPONSE_TIMEOUT` | No response or acknowledgment received during timeout period. | |

### otCoapToken

```
struct otCoapToken otCoapToken
```
Represents a CoAP message token.

### otCoapTxParameters

```
struct otCoapTxParameters otCoapTxParameters
```
Represents the CoAP transmission parameters.


> [!NOTE]
> **Note:** mAckTimeout \* ((2 \*\* (mMaxRetransmit + 1)) - 1) \* (mAckRandomFactorNumerator / mAckRandomFactorDenominator) must not exceed what can be represented by a uint32_t (0xffffffff). This limitation allows OpenThread to avoid 64-bit arithmetic.

<br />

### otCoapType

```
enum otCoapType otCoapType
```
CoAP Type values (2 bit unsigned integer).

## Functions

### otCoapAddBlockWiseResource

```
void otCoapAddBlockWiseResource(
  otInstance *aInstance,
  otCoapBlockwiseResource *aResource
)
```
Adds a block-wise resource to the CoAP server.

Requires `OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE`.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aResource` | A pointer to the resource. | |

### otCoapAddResource

```
void otCoapAddResource(
  otInstance *aInstance,
  otCoapResource *aResource
)
```
Adds a resource to the CoAP server.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aResource` | A pointer to the resource. | |

### otCoapBlockSizeFromExponent

```
uint16_t otCoapBlockSizeFromExponent(
  otCoapBlockSzx aSize
)
```
Converts a CoAP Block option SZX field to the actual block size.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aSize` | Block size exponent. | |
| **Returns** | The actual size exponent value. |

### otCoapMessageAppendBlock1Option

```
otError otCoapMessageAppendBlock1Option(
  otMessage *aMessage,
  uint32_t aNum,
  bool aMore,
  otCoapBlockSzx aSize
)
```
Appends a Block1 option.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aMessage` | A pointer to the CoAP message. | | `[in] aNum` | Current block number. | | `[in] aMore` | Boolean to indicate more blocks are to be sent. | | `[in] aSize` | Block Size Exponent. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully appended the option. | | `OT_ERROR_INVALID_ARGS` | The option type is not equal or greater than the last option type. | | `OT_ERROR_NO_BUFS` | The option length exceeds the buffer size. | |

### otCoapMessageAppendBlock2Option

```
otError otCoapMessageAppendBlock2Option(
  otMessage *aMessage,
  uint32_t aNum,
  bool aMore,
  otCoapBlockSzx aSize
)
```
Appends a Block2 option.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aMessage` | A pointer to the CoAP message. | | `[in] aNum` | Current block number. | | `[in] aMore` | Boolean to indicate more blocks are to be sent. | | `[in] aSize` | Block Size Exponent. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully appended the option. | | `OT_ERROR_INVALID_ARGS` | The option type is not equal or greater than the last option type. | | `OT_ERROR_NO_BUFS` | The option length exceeds the buffer size. | |

### otCoapMessageAppendContentFormatOption

```
otError otCoapMessageAppendContentFormatOption(
  otMessage *aMessage,
  otCoapOptionContentFormat aContentFormat
)
```
Appends the Content Format CoAP option as specified in <https://tools.ietf.org/html/rfc7252#page-92>.

This *must* be called before setting otCoapMessageSetPayloadMarker if a payload is to be included in the message.

The function is a convenience wrapper around otCoapMessageAppendUintOption, and if the desired format type code isn't listed in otCoapOptionContentFormat, this base function should be used instead.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aMessage` | A pointer to the CoAP message. | | `[in] aContentFormat` | One of the content formats listed in otCoapOptionContentFormat above. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully appended the option. | | `OT_ERROR_INVALID_ARGS` | The option type is not equal or greater than the last option type. | | `OT_ERROR_NO_BUFS` | The option length exceeds the buffer size. | |

### otCoapMessageAppendMaxAgeOption

```
otError otCoapMessageAppendMaxAgeOption(
  otMessage *aMessage,
  uint32_t aMaxAge
)
```
Appends a Max-Age option.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aMessage` | A pointer to the CoAP message. | | `[in] aMaxAge` | The Max-Age value. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully appended the option. | | `OT_ERROR_INVALID_ARGS` | The option type is not equal or greater than the last option type. | | `OT_ERROR_NO_BUFS` | The option length exceeds the buffer size. | |

### otCoapMessageAppendObserveOption

```
otError otCoapMessageAppendObserveOption(
  otMessage *aMessage,
  uint32_t aObserve
)
```
Appends an Observe option.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aMessage` | A pointer to the CoAP message. | | `[in] aObserve` | Observe field value. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully appended the option. | | `OT_ERROR_INVALID_ARGS` | The option type is not equal or greater than the last option type. | | `OT_ERROR_NO_BUFS` | The option length exceeds the buffer size. | |

### otCoapMessageAppendOption

```
otError otCoapMessageAppendOption(
  otMessage *aMessage,
  uint16_t aNumber,
  uint16_t aLength,
  const void *aValue
)
```
Appends a CoAP option in a header.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aMessage` | A pointer to the CoAP message. | | `[in] aNumber` | The CoAP Option number. | | `[in] aLength` | The CoAP Option length. | | `[in] aValue` | A pointer to the CoAP value. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully appended the option. | | `OT_ERROR_INVALID_ARGS` | The option type is not equal or greater than the last option type. | | `OT_ERROR_NO_BUFS` | The option length exceeds the buffer size. | |

### otCoapMessageAppendProxyUriOption

```
otError otCoapMessageAppendProxyUriOption(
  otMessage *aMessage,
  const char *aUriPath
)
```
Appends a Proxy-Uri option.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aMessage` | A pointer to the CoAP message. | | `[in] aUriPath` | A pointer to a NULL-terminated string. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully appended the option. | | `OT_ERROR_INVALID_ARGS` | The option type is not equal or greater than the last option type. | | `OT_ERROR_NO_BUFS` | The option length exceeds the buffer size. | |

### otCoapMessageAppendUintOption

```
otError otCoapMessageAppendUintOption(
  otMessage *aMessage,
  uint16_t aNumber,
  uint32_t aValue
)
```
Appends an unsigned integer CoAP option as specified in <https://tools.ietf.org/html/rfc7252#section-3.2>.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aMessage` | A pointer to the CoAP message. | | `[in] aNumber` | The CoAP Option number. | | `[in] aValue` | The CoAP Option unsigned integer value. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully appended the option. | | `OT_ERROR_INVALID_ARGS` | The option type is not equal or greater than the last option type. | | `OT_ERROR_NO_BUFS` | The option length exceeds the buffer size. | |

**See also:**   
otCoapMessageGetOptionUintValue   

### otCoapMessageAppendUriPathOptions

```
otError otCoapMessageAppendUriPathOptions(
  otMessage *aMessage,
  const char *aUriPath
)
```
Appends a Uri-Path option.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aMessage` | A pointer to the CoAP message. | | `[in] aUriPath` | A pointer to a NULL-terminated string. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully appended the option. | | `OT_ERROR_INVALID_ARGS` | The option type is not equal or greater than the last option type. | | `OT_ERROR_NO_BUFS` | The option length exceeds the buffer size. | |

### otCoapMessageAppendUriQueryOption

```
otError otCoapMessageAppendUriQueryOption(
  otMessage *aMessage,
  const char *aUriQuery
)
```
Appends a single Uri-Query option.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aMessage` | A pointer to the CoAP message. | | `[in] aUriQuery` | A pointer to NULL-terminated string, which should contain a single key=value pair. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully appended the option. | | `OT_ERROR_INVALID_ARGS` | The option type is not equal or greater than the last option type. | | `OT_ERROR_NO_BUFS` | The option length exceeds the buffer size. | |

### otCoapMessageAppendUriQueryOptions

```
otError otCoapMessageAppendUriQueryOptions(
  otMessage *aMessage,
  const char *aUriQuery
)
```
Appends a Uri-Query option.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aMessage` | A pointer to the CoAP message. | | `[in] aUriQuery` | A pointer to a NULL-terminated string. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully appended the option. | | `OT_ERROR_INVALID_ARGS` | The option type is not equal or greater than the last option type. | | `OT_ERROR_NO_BUFS` | The option length exceeds the buffer size. | |

### otCoapMessageAreTokensEqual

```
bool otCoapMessageAreTokensEqual(
  const otCoapToken *aFirstToken,
  const otCoapToken *aSecondToken
)
```
Indicates whether two given CoAP Tokens are equal.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aFirstToken` | The first Token to compare. | | `[in] aSecondToken` | The second Token to compare. | |
| Return Values | |---|---| | `TRUE` | If the two Tokens are equal. | | `FALSE` | If the two Tokens are not equal. | |

### otCoapMessageCodeToString

```
const char * otCoapMessageCodeToString(
  const otMessage *aMessage
)
```
Returns the CoAP Code as human readable string.


@ returns The CoAP Code as string.

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aMessage` | A pointer to the CoAP message. | |

### otCoapMessageGenerateToken

```
void otCoapMessageGenerateToken(
  otMessage *aMessage,
  uint8_t aTokenLength
)
```
Writes a randomly generated Token of a given length in the CoAP message.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aMessage` | The CoAP message. | | `[in] aTokenLength` | The Length of a Token (in bytes). | |

### otCoapMessageGetCode

```
otCoapCode otCoapMessageGetCode(
  const otMessage *aMessage
)
```
Returns the Code value.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aMessage` | A pointer to the CoAP message. | |
| **Returns** | The Code value. |

### otCoapMessageGetMessageId

```
uint16_t otCoapMessageGetMessageId(
  const otMessage *aMessage
)
```
Returns the Message ID value.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aMessage` | A pointer to the CoAP message. | |
| **Returns** | The Message ID value. |

### otCoapMessageGetToken

```
const uint8_t * otCoapMessageGetToken(
  const otMessage *aMessage
)
```
Returns a pointer to the Token value.

**[Deprecated.](https://openthread.io/reference/deprecated/deprecated)** This function is deprecated. Use `https://openthread.io/reference/group/api-coap#group__api-coap_1gaffe4877b326ea8a1de335eb5a7b49928` instead.


> [!NOTE]
> **Note:** A previously returned pointer (`const uint8_t *`) will be invalidated upon the next call to this function.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aMessage` | A pointer to the CoAP message. | |
| **Returns** | A pointer to the Token value. |

### otCoapMessageGetTokenLength

```
uint8_t otCoapMessageGetTokenLength(
  const otMessage *aMessage
)
```
Returns the Token length.

**[Deprecated.](https://openthread.io/reference/deprecated/deprecated)** This function is deprecated. Use `https://openthread.io/reference/group/api-coap#group__api-coap_1gaffe4877b326ea8a1de335eb5a7b49928` instead.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aMessage` | A pointer to the CoAP message. | |
| **Returns** | The Token length. |

### otCoapMessageGetType

```
otCoapType otCoapMessageGetType(
  const otMessage *aMessage
)
```
Returns the Type value.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aMessage` | A pointer to the CoAP message. | |
| **Returns** | The Type value. |

### otCoapMessageInit

```
otError otCoapMessageInit(
  otMessage *aMessage,
  otCoapType aType,
  otCoapCode aCode
)
```
Initializes a CoAP message.

This function initializes the CoAP header, erasing any previously written content in the message. The Message ID is set to zero, and the token is empty (zero-length).

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aMessage` | A pointer to the CoAP message to initialize. | | `[in] aType` | The CoAP Type. | | `[in] aCode` | The CoAP Code. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully initialized the message. | | `OT_ERROR_NO_BUFS` | Insufficient message buffers available to write the CoAP header. | |

### otCoapMessageInitResponse

```
otError otCoapMessageInitResponse(
  otMessage *aResponse,
  const otMessage *aRequest,
  otCoapType aType,
  otCoapCode aCode
)
```
Initializes a CoAP message as a response to a request.

This function initializes the CoAP header, erasing any previously written content in the message. The Message ID and Token are copied from the request message.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aResponse` | A pointer to the CoAP response message to initialize. | | `[in] aRequest` | A pointer to the CoAP request message. | | `[in] aType` | The CoAP Type for the response. | | `[in] aCode` | The CoAP Code for the response. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully initialized the response message. | | `OT_ERROR_NO_BUFS` | Insufficient message buffers available to write the CoAP header. | |

### otCoapMessageReadToken

```
otError otCoapMessageReadToken(
  const otMessage *aMessage,
  otCoapToken *aToken
)
```
Reads the Token from the CoAP message.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aMessage` | The CoAP message. | | `[out] aToken` | A pointer to a `https://openthread.io/reference/struct/ot-coap-token` to output the read Token. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully read the Token. `aToken` is updated. | | `OT_ERROR_PARSE` | Failed to parse the header. | |

### otCoapMessageSetCode

```
void otCoapMessageSetCode(
  otMessage *aMessage,
  otCoapCode aCode
)
```
Sets the Code value.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aMessage` | A pointer to the CoAP message to initialize. | | `[in] aCode` | CoAP message code. | |

### otCoapMessageSetPayloadMarker

```
otError otCoapMessageSetPayloadMarker(
  otMessage *aMessage
)
```
Adds Payload Marker indicating beginning of the payload to the CoAP header.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aMessage` | A pointer to the CoAP message. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Payload Marker successfully added. | | `OT_ERROR_NO_BUFS` | Header Payload Marker exceeds the buffer size. | |

### otCoapMessageSetToken

```
otError otCoapMessageSetToken(
  otMessage *aMessage,
  const uint8_t *aToken,
  uint8_t aTokenLength
)
```
Sets the Token value and length in a CoAP message.

**[Deprecated.](https://openthread.io/reference/deprecated/deprecated)** This function is deprecated. Use `https://openthread.io/reference/group/api-coap#group__api-coap_1ga116ebe406acb72f618e56b1ec5a607ef` instead.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aMessage` | A pointer to the CoAP message. | | `[in] aToken` | A pointer to the Token value. | | `[in] aTokenLength` | The Length of `aToken`. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully set the Token value. | | `OT_ERROR_NO_BUFS` | Insufficient buffers to set the Token value. | |

### otCoapMessageWriteToken

```
otError otCoapMessageWriteToken(
  otMessage *aMessage,
  const otCoapToken *aToken
)
```
Writes the Token in the CoAP message.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aMessage` | The CoAP message. | | `[in] aToken` | The Token to write. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully wrote the Token. | | `OT_ERROR_NO_BUFS` | Insufficient buffers to set the Token value. | |

### otCoapNewMessage

```
otMessage * otCoapNewMessage(
  otInstance *aInstance,
  const otMessageSettings *aSettings
)
```
Creates a new CoAP message.


> [!NOTE]
> **Note:** If `aSettings` is 'NULL', the link layer security is enabled and the message priority is set to OT_MESSAGE_PRIORITY_NORMAL by default.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aSettings` | A pointer to the message settings or NULL to set default settings. | |
| **Returns** | A pointer to the message buffer or NULL if no message buffers are available or parameters are invalid. |

### otCoapOptionIteratorGetFirstOption

```
const otCoapOption * otCoapOptionIteratorGetFirstOption(
  otCoapOptionIterator *aIterator
)
```
Returns a pointer to the first option.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aIterator` | A pointer to the CoAP message option iterator. | |
| **Returns** | A pointer to the first option. If no option is present NULL pointer is returned. |

### otCoapOptionIteratorGetFirstOptionMatching

```
const otCoapOption * otCoapOptionIteratorGetFirstOptionMatching(
  otCoapOptionIterator *aIterator,
  uint16_t aOption
)
```
Returns a pointer to the first option matching the specified option number.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aIterator` | A pointer to the CoAP message option iterator. | | `[in] aOption` | The option number sought. | |
| **Returns** | A pointer to the first matching option. If no matching option is present NULL pointer is returned. |

### otCoapOptionIteratorGetNextOption

```
const otCoapOption * otCoapOptionIteratorGetNextOption(
  otCoapOptionIterator *aIterator
)
```
Returns a pointer to the next option.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aIterator` | A pointer to the CoAP message option iterator. | |
| **Returns** | A pointer to the next option. If no more options are present NULL pointer is returned. |

### otCoapOptionIteratorGetNextOptionMatching

```
const otCoapOption * otCoapOptionIteratorGetNextOptionMatching(
  otCoapOptionIterator *aIterator,
  uint16_t aOption
)
```
Returns a pointer to the next option matching the specified option number.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aIterator` | A pointer to the CoAP message option iterator. | | `[in] aOption` | The option number sought. | |
| **Returns** | A pointer to the next matching option. If no further matching option is present NULL pointer is returned. |

### otCoapOptionIteratorGetOptionUintValue

```
otError otCoapOptionIteratorGetOptionUintValue(
  otCoapOptionIterator *aIterator,
  uint64_t *aValue
)
```
Fills current option value into `aValue` assuming the current value is an unsigned integer encoded according to <https://tools.ietf.org/html/rfc7252#section-3.2>.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aIterator` | A pointer to the CoAP message option iterator. | | `[out] aValue` | A pointer to an unsigned integer to receive the option value. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully filled value. | | `OT_ERROR_NOT_FOUND` | No current option. | | `OT_ERROR_NO_BUFS` | Value is too long to fit in a uint64_t. | |

**See also:**   
[otCoapMessageAppendUintOption](https://openthread.io/reference/group/api-coap#group__api-coap_1ga39c26403482aa325e260fca09ef4967d)   

### otCoapOptionIteratorGetOptionValue

```
otError otCoapOptionIteratorGetOptionValue(
  otCoapOptionIterator *aIterator,
  void *aValue
)
```
Fills current option value into `aValue`.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aIterator` | A pointer to the CoAP message option iterator. | | `[out] aValue` | A pointer to a buffer to receive the option value. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully filled value. | | `OT_ERROR_NOT_FOUND` | No current option. | |

### otCoapOptionIteratorInit

```
otError otCoapOptionIteratorInit(
  otCoapOptionIterator *aIterator,
  const otMessage *aMessage
)
```
Initializes an iterator for the options in the given message.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in,out] aIterator` | A pointer to the CoAP message option iterator. | | `[in] aMessage` | A pointer to the CoAP message. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully initialized. | | `OT_ERROR_PARSE` | Message state is inconsistent. | |

### otCoapRemoveBlockWiseResource

```
void otCoapRemoveBlockWiseResource(
  otInstance *aInstance,
  otCoapBlockwiseResource *aResource
)
```
Removes a block-wise resource from the CoAP server.

Requires `OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE`.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aResource` | A pointer to the resource. | |

### otCoapRemoveResource

```
void otCoapRemoveResource(
  otInstance *aInstance,
  otCoapResource *aResource
)
```
Removes a resource from the CoAP server.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aResource` | A pointer to the resource. | |

### otCoapSendRequest

```
otError otCoapSendRequest(
  otInstance *aInstance,
  otMessage *aMessage,
  const otMessageInfo *aMessageInfo,
  otCoapResponseHandler aHandler,
  void *aContext
)
```
Sends a CoAP request.

If a response for a request is expected, respective function and context information should be provided. If no response is expected, these arguments should be NULL pointers.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aMessage` | A pointer to the message to send. | | `[in] aMessageInfo` | A pointer to the message info associated with `aMessage`. | | `[in] aHandler` | A function pointer that shall be called on response reception or timeout. | | `[in] aContext` | A pointer to arbitrary context information. May be NULL if not used. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully sent CoAP message. | | `OT_ERROR_NO_BUFS` | Failed to allocate retransmission data. | |

### otCoapSendRequestBlockWise

```
otError otCoapSendRequestBlockWise(
  otInstance *aInstance,
  otMessage *aMessage,
  const otMessageInfo *aMessageInfo,
  otCoapResponseHandler aHandler,
  void *aContext,
  otCoapBlockwiseTransmitHook aTransmitHook,
  otCoapBlockwiseReceiveHook aReceiveHook
)
```
Sends a CoAP request block-wise.

Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.

If a response for a request is expected, respective function and context information should be provided. If the response is expected to be block-wise, a respective hook function should be provided. If no response is expected, these arguments should be NULL pointers.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aMessage` | A pointer to the message to send. | | `[in] aMessageInfo` | A pointer to the message info associated with `aMessage`. | | `[in] aHandler` | A function pointer that shall be called on response reception or timeout. | | `[in] aContext` | A pointer to arbitrary context information. May be NULL if not used. | | `[in] aTransmitHook` | A pointer to a hook function for outgoing block-wise transfer. | | `[in] aReceiveHook` | A pointer to a hook function for incoming block-wise transfer. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully sent CoAP message. | | `OT_ERROR_NO_BUFS` | Failed to allocate retransmission data. | |

### otCoapSendRequestBlockWiseWithParameters

```
otError otCoapSendRequestBlockWiseWithParameters(
  otInstance *aInstance,
  otMessage *aMessage,
  const otMessageInfo *aMessageInfo,
  otCoapResponseHandler aHandler,
  void *aContext,
  const otCoapTxParameters *aTxParameters,
  otCoapBlockwiseTransmitHook aTransmitHook,
  otCoapBlockwiseReceiveHook aReceiveHook
)
```
Sends a CoAP request block-wise with custom transmission parameters.

Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.

If a response for a request is expected, respective function and context information should be provided. If the response is expected to be block-wise, a respective hook function should be provided. If no response is expected, these arguments should be NULL pointers.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aMessage` | A pointer to the message to send. | | `[in] aMessageInfo` | A pointer to the message info associated with `aMessage`. | | `[in] aHandler` | A function pointer that shall be called on response reception or timeout. | | `[in] aContext` | A pointer to arbitrary context information. May be NULL if not used. | | `[in] aTxParameters` | A pointer to transmission parameters for this request. Use NULL for defaults. | | `[in] aTransmitHook` | A pointer to a hook function for outgoing block-wise transfer. | | `[in] aReceiveHook` | A pointer to a hook function for incoming block-wise transfer. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully sent CoAP message. | | `OT_ERROR_NO_BUFS` | Failed to allocate retransmission data. | | `OT_ERROR_INVALID_ARGS` | Invalid arguments are given. | |

### otCoapSendRequestWithParameters

```
otError otCoapSendRequestWithParameters(
  otInstance *aInstance,
  otMessage *aMessage,
  const otMessageInfo *aMessageInfo,
  otCoapResponseHandler aHandler,
  void *aContext,
  const otCoapTxParameters *aTxParameters
)
```
Sends a CoAP request with custom transmission parameters.

If a response for a request is expected, respective function and context information should be provided. If no response is expected, these arguments should be NULL pointers.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aMessage` | A pointer to the message to send. | | `[in] aMessageInfo` | A pointer to the message info associated with `aMessage`. | | `[in] aHandler` | A function pointer that shall be called on response reception or timeout. | | `[in] aContext` | A pointer to arbitrary context information. May be NULL if not used. | | `[in] aTxParameters` | A pointer to transmission parameters for this request. Use NULL for defaults. Otherwise, parameters given must meet the following conditions: 1. mMaxRetransmit is no more than OT_COAP_MAX_RETRANSMIT. 2. mAckRandomFactorNumerator / mAckRandomFactorDenominator must not be below 1.0. 3. The calculated exchange life time must not overflow uint32_t. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully sent CoAP message. | | `OT_ERROR_NO_BUFS` | Failed to allocate retransmission data. | | `OT_ERROR_INVALID_ARGS` | Invalid arguments are given. | |

### otCoapSendResponse

```
otError otCoapSendResponse(
  otInstance *aInstance,
  otMessage *aMessage,
  const otMessageInfo *aMessageInfo
)
```
Sends a CoAP response from the server.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aMessage` | A pointer to the CoAP response to send. | | `[in] aMessageInfo` | A pointer to the message info associated with `aMessage`. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully enqueued the CoAP response message. | | `OT_ERROR_NO_BUFS` | Insufficient buffers available to send the CoAP response. | |

### otCoapSendResponseBlockWise

```
otError otCoapSendResponseBlockWise(
  otInstance *aInstance,
  otMessage *aMessage,
  const otMessageInfo *aMessageInfo,
  void *aContext,
  otCoapBlockwiseTransmitHook aTransmitHook
)
```
Sends a CoAP response block-wise from the server.

Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aMessage` | A pointer to the CoAP response to send. | | `[in] aMessageInfo` | A pointer to the message info associated with `aMessage`. | | `[in] aContext` | A pointer to arbitrary context information. May be NULL if not used. | | `[in] aTransmitHook` | A pointer to a hook function for outgoing block-wise transfer. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully enqueued the CoAP response message. | | `OT_ERROR_NO_BUFS` | Insufficient buffers available to send the CoAP response. | |

### otCoapSendResponseBlockWiseWithParameters

```
otError otCoapSendResponseBlockWiseWithParameters(
  otInstance *aInstance,
  otMessage *aMessage,
  const otMessageInfo *aMessageInfo,
  const otCoapTxParameters *aTxParameters,
  void *aContext,
  otCoapBlockwiseTransmitHook aTransmitHook
)
```
Sends a CoAP response block-wise from the server with custom transmission parameters.

Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aMessage` | A pointer to the CoAP response to send. | | `[in] aMessageInfo` | A pointer to the message info associated with `aMessage`. | | `[in] aTxParameters` | A pointer to transmission parameters for this response. Use NULL for defaults. | | `[in] aContext` | A pointer to arbitrary context information. May be NULL if not used. | | `[in] aTransmitHook` | A pointer to a hook function for outgoing block-wise transfer. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully enqueued the CoAP response message. | | `OT_ERROR_NO_BUFS` | Insufficient buffers available to send the CoAP response. | | `OT_ERROR_INVALID_ARGS` | Invalid arguments are given. | |

### otCoapSendResponseWithParameters

```
otError otCoapSendResponseWithParameters(
  otInstance *aInstance,
  otMessage *aMessage,
  const otMessageInfo *aMessageInfo,
  const otCoapTxParameters *aTxParameters
)
```
Sends a CoAP response from the server with custom transmission parameters.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aMessage` | A pointer to the CoAP response to send. | | `[in] aMessageInfo` | A pointer to the message info associated with `aMessage`. | | `[in] aTxParameters` | A pointer to transmission parameters for this response. Use NULL for defaults. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully enqueued the CoAP response message. | | `OT_ERROR_NO_BUFS` | Insufficient buffers available to send the CoAP response. | | `OT_ERROR_INVALID_ARGS` | Invalid arguments are given. | |

### otCoapSetDefaultHandler

```
void otCoapSetDefaultHandler(
  otInstance *aInstance,
  otCoapRequestHandler aHandler,
  void *aContext
)
```
Sets the default handler for unhandled CoAP requests.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aHandler` | A function pointer that shall be called when an unhandled request arrives. | | `[in] aContext` | A pointer to arbitrary context information. May be NULL if not used. | |

### otCoapSetResponseFallback

```
void otCoapSetResponseFallback(
  otInstance *aInstance,
  otCoapResponseFallback aHandler,
  void *aContext
)
```
Sets a fallback handler for CoAP responses not matching any active/pending request.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aHandler` | A function pointer that shall be called as a fallback for responses without matching active/pending CoAP requests. | | `[in] aContext` | A pointer to arbitrary context information. May be NULL if not used. | |

### otCoapStart

```
otError otCoapStart(
  otInstance *aInstance,
  uint16_t aPort
)
```
Starts the CoAP server.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aPort` | The local UDP port to bind to. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully started the CoAP server. | | `OT_ERROR_FAILED` | Failed to start the CoAP server. | |

### otCoapStop

```
otError otCoapStop(
  otInstance *aInstance
)
```
Stops the CoAP server.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | Successfully stopped the CoAP server. | |

## Macros

### OT_COAP_CODE

```
 OT_COAP_CODE ((((c) & 0x7) << 5) | ((d) & 0x1f))
```
Helper macro to define CoAP Code values.

### OT_COAP_DEFAULT_TOKEN_LENGTH

```
 OT_COAP_DEFAULT_TOKEN_LENGTH 2
```
Default token length.

### OT_COAP_MAX_RETRANSMIT

```
 OT_COAP_MAX_RETRANSMIT 20
```
Max retransmit supported by OpenThread.

### OT_COAP_MAX_TOKEN_LENGTH

```
 OT_COAP_MAX_TOKEN_LENGTH 8
```
Max token length as specified (RFC 7252).

### OT_COAP_MIN_ACK_TIMEOUT

```
 OT_COAP_MIN_ACK_TIMEOUT 1000
```
Minimal ACK timeout in milliseconds supported by OpenThread.

### OT_DEFAULT_COAP_PORT

```
 OT_DEFAULT_COAP_PORT 5683
```
Default CoAP port, as specified in RFC 7252.

## Resources

OpenThread API Reference topics originate from the source code, available
on [GitHub](https://github.com/openthread/openthread/tree/main/include/openthread).
For more information, or to contribute to our documentation, refer to
[Resources](https://openthread.io/resources).