libfetch 0.0.0
A lightweight asynchronous HTTP/1.1 client library implementing a subset of the WHATWG Fetch API.
Loading...
Searching...
No Matches
Request Initialization

Functions for configuring requests. More...

Functions

fetch_init_tfetch_init_new (void)
 Create a new request configuration.
 
void fetch_init_free (fetch_init_t *init)
 Free a request configuration.
 
fetch_init_tfetch_init_method (fetch_init_t *init, http_method_t method)
 Set HTTP method (fluent interface)
 
fetch_init_tfetch_init_headers (fetch_init_t *init, fetch_headers_t *headers)
 Set request headers (fluent interface)
 
fetch_init_tfetch_init_body (fetch_init_t *init, fetch_body_t *body)
 Set request body (fluent interface)
 
fetch_init_tfetch_init_timeout (fetch_init_t *init, uint32_t timeout_ms)
 Set request timeout (fluent interface)
 
fetch_init_tfetch_init_signal (fetch_init_t *init, fetch_abort_controller_t *signal)
 Set abort signal (fluent interface)
 

Detailed Description

Functions for configuring requests.

Function Documentation

◆ fetch_init_body()

fetch_init_t * fetch_init_body ( fetch_init_t * init,
fetch_body_t * body )

Set request body (fluent interface)

Parameters
initInit object
bodyBody object (ownership transferred to init)
Returns
Same init object for chaining
Note
Memory: Ownership of body is transferred to init

◆ fetch_init_free()

void fetch_init_free ( fetch_init_t * init)

Free a request configuration.

Parameters
initInit object to free (can be NULL)
Note
Memory: Frees the init object and all owned resources (headers, body, etc.)

◆ fetch_init_headers()

fetch_init_t * fetch_init_headers ( fetch_init_t * init,
fetch_headers_t * headers )

Set request headers (fluent interface)

Parameters
initInit object
headersHeaders object (ownership transferred to init)
Returns
Same init object for chaining
Note
Memory: Ownership of headers is transferred to init

◆ fetch_init_method()

fetch_init_t * fetch_init_method ( fetch_init_t * init,
http_method_t method )

Set HTTP method (fluent interface)

Parameters
initInit object
methodHTTP method
Returns
Same init object for chaining

◆ fetch_init_new()

fetch_init_t * fetch_init_new ( void )

Create a new request configuration.

Returns
New init object with default values (caller owns, must call fetch_init_free()), or NULL on failure
Note
Memory: Returns owned object that must be freed
if (!init) {
fprintf(stderr, "Failed to create init\n");
return -1;
}
// Configure request (these functions transfer ownership)
fetch_init_timeout(init, 10000); // 10 seconds
fetch_headers_set(headers, "Content-Type", "application/json");
fetch_init_headers(init, headers); // Ownership of headers transferred to
init
fetch_body_t *body = fetch_body_json("{\"test\": true}");
fetch_init_body(init, body); // Ownership of body transferred to init
// Use init with request...
fetch_init_free(init); // Required: frees init, headers, and body
fetch_body_t * fetch_body_json(const char *json)
Create a JSON body.
Definition fetch.c:8228
fetch_headers_t * fetch_headers_new(void)
Create a new headers container.
Definition fetch.c:8028
void fetch_headers_set(fetch_headers_t *headers, const char *name, const char *value)
Set a header (replaces existing)
Definition fetch.c:8131
@ HTTP_METHOD_POST
Definition fetch.h:232
void fetch_init_free(fetch_init_t *init)
Free a request configuration.
Definition fetch.c:8881
fetch_init_t * fetch_init_method(fetch_init_t *init, http_method_t method)
Set HTTP method (fluent interface)
Definition fetch.c:8891
fetch_init_t * fetch_init_headers(fetch_init_t *init, fetch_headers_t *headers)
Set request headers (fluent interface)
Definition fetch.c:8897
fetch_init_t * fetch_init_timeout(fetch_init_t *init, uint32_t timeout_ms)
Set request timeout (fluent interface)
Definition fetch.c:8913
fetch_init_t * fetch_init_new(void)
Create a new request configuration.
Definition fetch.c:8861
fetch_init_t * fetch_init_body(fetch_init_t *init, fetch_body_t *body)
Set request body (fluent interface)
Definition fetch.c:8905
Request or response body.
Definition fetch.h:441
HTTP headers container.
Definition fetch.h:393
Request configuration options.
Definition fetch.h:482

◆ fetch_init_signal()

fetch_init_t * fetch_init_signal ( fetch_init_t * init,
fetch_abort_controller_t * signal )

Set abort signal (fluent interface)

Parameters
initInit object
signalAbort controller (borrowed reference, init does not own)
Returns
Same init object for chaining
Note
Memory: Controller is borrowed, caller must keep it alive and free it

◆ fetch_init_timeout()

fetch_init_t * fetch_init_timeout ( fetch_init_t * init,
uint32_t timeout_ms )

Set request timeout (fluent interface)

Parameters
initInit object
timeout_msTimeout in milliseconds
Returns
Same init object for chaining