C Collections

chttpserver · Section 3

chttpsvr_resp_write_json

chttpsvr_resp_write_json - append JSON to the response body

C Collections (libccollections, -lccollections)

#include <ccollections/chttpserver.h>
 
ccol_retval chttpsvr_resp_write_json(chttpsvr_resp *resp,
                                        const char *json, size_t len);

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.

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.

chttpsvr_resp_write(3), chttpsvr_resp_set_header(3)