I have written a blog post about the current effort to revamp @RIOT_OS's nanocoap API. I try to analyse what the current state is, how we got there, and a potential vision for the future.

https://mari-bu.de/blog/20260222-nanocoap-api/

Breaking API Changes for nanocoap

RIOT, an open source OS for MCU class IoT devices, supports multiple CoAP implementations, both externally maintained code packaged as well as currently three internal ones. The oldest among them is nanocoap, for which I have proposed a larger set of breaking API changes as a pull request today. tl;dr: User Facing Changes Changes By Example A resource handler that was implemented like this before: static ssize_t _foo_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len, coap_request_ctx_t *context) { static const char *payload = "Hello World"; const size_t payload_len = strlen(payload); // Worst case estimation of the data to add: size_t max_data_len = COAP_OPT_FOO_MAX_LEN + COAP_OPT_BAR_MAX_LEN + COAP_PAYLOAD_MARKER_SIZE + payload_len; ssize_t hdr_len = coap_build_reply(pkt, COAP_CODE_CONTENT, buf, len, max_data_len); if (hdr_len < 0) { return hdr_len; // pass through error } // This step is needed due to an API design flaw hdr_len -= max_data_len; uint8_t *pos = buf + hdr_len; uint16_t lastonum = 0; pos += coap_opt_put_uint(buf, lastonum, COAP_OPT_FOO, 42); lastonum = COAP_OPT_FOO; pos += coap_opt_put_uint(buf, lastonum, COAP_OPT_BAR, 1337); *pos++ = COAP_PAYLOAD_MARKER; memcpy(pos, payload, payload_len); pos += payload_len; return (uintptr_t)pos - (uintptr_t)buf; } Now needs to be implemented like this:

Marian Buschsieweke