chttpserver · Section 3
chttpsvr_resp_write_json
NAME
chttpsvr_resp_write_json - append JSON to the response body
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/chttpserver.h>
ccol_retval chttpsvr_resp_write_json(chttpsvr_resp *resp,
const char *json, size_t len);
DESCRIPTION
Appends len bytes of json to the response body and then sets the Content-Type response header to "application/json". The body is written first, so when the body allocation runs out of memory resp is left exactly as it was, with no header installed and no bytes buffered. If resp or json is NULL, or len is 0, the function returns ccol_invalid_args at once and changes nothing in resp. A JSON body of zero bytes with that Content-Type has no valid meaning, so it is refused instead of setting the header with nothing behind it.
RETURN VALUE
ccol_success - The body bytes were appended and the
Content-Type header was set.
ccol_invalid_args - resp or json is NULL, or len is 0.
ccol_not_enough_memory - The allocation of the body buffer or of the
header buffer failed.