PMHTTPNEWCLIENT(3)

πŸ“¦
version 7.2.2 Β· 3 versions
, in arch rolling, centos-stream 10, fedora 43, fedora 44, ubuntu resolute, ubuntu stonking

πŸ’… PMHTTPNEWCLIENT β€” like, the whole HTTP client thing

okay bestie, welcome to PMHTTPNEWCLIENT(3), a page from the Library Functions Manual ✨. It's the group chat of three little functions β€” pmhttpNewClient, pmhttpFreeClient and pmhttpClientFetch β€” and together they're the simple HTTP client interfaces 🌸. Lowkey iconic.


✨ C SYNOPSIS ✨

first things first, you gotta pull in the headers, no cap:

#include <pcp/pmapi.h>
#include <pcp/pmhttp.h>

struct http_client *pmhttpNewClient(void);
void pmhttpFreeClient(struct http_client *client);
int pmhttpClientFetch(struct http_client *client, const char *url,
                      char *bodybuf, size_t bodylen, char *typebuf,
                      size_t typelen);

and when you link, you link it like this, periodt:

cc ... -lpcp_web

🌈 DESCRIPTION 🌈

okay so. pmhttpNewClient allocates and initializes an opaque HTTP client for you β€” it comes out ready to make requests from a server. That's it, that's the whole job. She's fresh, she's ready, she's got main character energy πŸ‘‘

Now the URL request interface, pmhttpClientFetch, is the one that actually does the talking: it issues an HTTP GET request to the server you named in the url you handed it πŸ“¨. The body of the response comes back to you in the caller-supplied bodybuf buffer, which is bodylen bytes long. You can also pass an optional typebuf buffer of typelen bytes β€” and if it's non-NULL it'll hold the value of the content-type header the server sent back πŸŽ€.

The url parameter is an RFC1630 format URL. Usually that means it's prefixed with "http://", but listen β€” these interfaces also support Unix domain sockets πŸ¦‹. Those get prefixed with "unix://" instead, followed by the full filesystem path to the Unix domain socket you want. iykyk.

And when you're done and you need to free up the resources tied to an HTTP client β€” including closing any persistent server connection that got established earlier β€” that's pmhttpFreeClient's moment πŸ’…. She cleans up. She closes the connection. She says bye 🫢.


πŸ”₯ DIAGNOSTICS πŸ”₯

pmhttpNewClient will hand you back NULL on failure, and ngl there's literally only one way that happens: when allocation of memory is just not possible 😭.

pmhttpClientFetch will return the number of bytes placed into the bodybuf buffer, or else a negated error code telling you the nature of the failure. So if you see a negative number, that's your vibe check failing, bestie πŸ’€.


πŸ‘‘ SEE ALSO πŸ‘‘

go read these, they're all part of the lore:


and that's the whole page, fr fr β€” brought to you by Performance Co-Pilot (that's the PCP girlies 🌈) and yeah, this is the PMHTTPNEWCLIENT(3) page, mwah πŸ’–

πŸ“¦ where this page comes from