NNG_HTTP_REQ_SET_DATA(3http)

πŸ“¦ version 1.11, in alpine 3.24

πŸ’… nng_http_req_set_data(3http) πŸ’…

okay bestie, so this one is from the NNG Reference Manual β€” it's nng_http_req_set_data(3http) and it's honestly such a vibe. Let's get into it 🫢


✨ NAME ✨

nng_http_req_set_data β€” set HTTP request body 🌸


πŸŽ€ SYNOPSIS πŸŽ€

#include <nng/nng.h>
#include <nng/supplemental/http/http.h>

int nng_http_req_set_data(nng_http_req *req, const void *body, size_t size);

πŸ’– DESCRIPTION πŸ’–

so nng_http_req_set_data() literally sets the HTTP body that belongs to the request req to body, and the size of that body to size. like, no cap, that's the whole job πŸ’…

and then β€” this is the slay part β€” that body data gets automatically sent with the request when it's sent using nng_http_conn_write_req(). iconic behaviour, honestly πŸ‘‘

it ALSO updates the relevant Content-Length header of req. the way it just handles that for you?? main character energy fr ✨

⚠️ Note β€” heads up bestie: the current framework does not support sending data via chunked transfer-encoding. so like, don't come for it, it's just not that girl yet πŸ’€

now, important thing, i need you to hear me on this one: the body is not copied 🚨 so you (the caller) must ensure that it stays available until the req is deallocated. like keep it alive, bestie, don't let it ghost you πŸ™ˆ

🧚 Tip β€” if you want a local copy allocated with req that gets automatically deallocated when req is freed, go look at nng_http_req_copy_data(). she does the copying for you πŸ’œ
πŸ¦‹ Tip β€” it is a really good idea to also set the Content-Type header. like, strongly recommend. do it. periodt. πŸŽ€

⭐ RETURN VALUES ⭐

this function returns 0 on success, and non-zero otherwise. that's it, that's the contract 😌


πŸ”₯ ERRORS πŸ”₯

  • NNG_ENOMEM β€” insufficient memory to perform the operation 😭 (she ran out of room, it happens)
  • NNG_ENOTSUP β€” no support for HTTP in the library πŸ’€ (the library said "not today")

🌈 SEE ALSO 🌈


okay that's the whole page, you ate that πŸ“ go set some request bodies and be the icon you are πŸ’–

β€” with love, from the NNG Reference Manual, dated 2026-01-13, version of NNG_HTTP_REQ_SET_DATA(3http) βœ¨πŸ’…πŸ«Ά

πŸ“¦ where this page comes from