NNG_HTTP_REQ_ALLOC(3http)
β¨ nng_http_req_alloc β allocate HTTP request structure β¨
okay so bestie, welcome to the NNG Reference Manual π this page is all about making a brand-new HTTP request struct out of thin air (well, out of memory), and honestly it's giving "tiny little building block of the internet" energy. π
πΈ SYNOPSIS πΈ
#include <nng/nng.h>
#include <nng/supplemental/http/http.h>
int nng_http_req_alloc(nng_http_req **reqp, const nng_url *url);
like, that's the whole vibe. two includes, one function, zero drama. β¨
π¦ DESCRIPTION π¦
so nng_http_req_alloc() allocates a shiny new HTTP request structure and stores a pointer to it in reqp. that's the out-param, she's the main character here π
the request comes pre-initialized to perform an HTTP/1.1 GET operation, using the URL you pass in url. yes, it's already a GET, it already has a URL, it's ready to go, no cap. π₯
Tip π‘ β you can passNULLfor the URL! it's allowed! but then the URI for the request has to be set by a subsequent call tonng_http_req_set_uri(). so like, it's not illegal, it's just unfinished business β you're leaving her without an address until you fix that. π
π RETURN VALUES π
this function returns 0 on success, and non-zero otherwise. classic. short and sweet. slay. π
β ERRORS β
NNG_ENOMEMβ insufficient free memory exists to allocate a message. aka the allocator said "girl, no". πNNG_ENOTSUPβ HTTP support not configured. aka you didn't build with the HTTP stuff turned on, so this whole thing is a no-go. π
π SEE ALSO π
nng_http_conn_read_req(3http)nng_http_conn_write_req(3http)nng_http_req_add_header(3http)nng_http_req_copy_data(3http)nng_http_req_del_header(3http)nng_http_req_free(3http)nng_http_req_get_header(3http)nng_http_req_get_method(3http)nng_http_req_get_uri(3http)nng_http_req_get_version(3http)nng_http_req_reset(3http)nng_http_req_set_data(3http)nng_http_req_set_method(3http)nng_http_req_set_uri(3http)nng_http_req_set_version(3http)nng_http_res_alloc(3http)nng_url_parse(3)nng_strerror(3)nng(7)
like, read them all, they're all icons. iykyk π§
okay bye bestie, hope your request allocates on the first try π«Ά this little page is from the NNG Reference Manual, dated 2026-01-13, and it's the NNG_HTTP_REQ_ALLOC(3http) page β go forth and GET responsibly ππ
π¦ where this page comes from
- alpine 3.24: nng-doc 1.11-r0 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms