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

Helper functions for common operations. More...

Functions

const char * fetch_method_to_string (http_method_t method)
 Convert HTTP method enum to string.
 
http_method_t fetch_method_from_string (const char *method_str)
 Convert string to HTTP method enum.
 
bool fetch_is_valid_url (const char *url)
 Check if a URL is valid.
 
const char * fetch_error_to_string (fetch_error_t error)
 Convert error code to human-readable string.
 

Detailed Description

Helper functions for common operations.

Function Documentation

◆ fetch_error_to_string()

const char * fetch_error_to_string ( fetch_error_t error)

Convert error code to human-readable string.

Parameters
errorError code
Returns
Error description string (static, do not free)
Note
Memory: Returned string is static, do not free
if (fetch_promise_rejected(promise)) {
printf("Error: %s\n", fetch_error_to_string(error));
}
fetch_error_t
Error codes for fetch operations.
Definition fetch.h:341
fetch_error_t fetch_promise_error(const fetch_promise_t *promise)
Get the error code from a rejected promise.
Definition fetch.c:8008
bool fetch_promise_rejected(const fetch_promise_t *promise)
Check if promise was rejected.
Definition fetch.c:8024
const char * fetch_error_to_string(fetch_error_t error)
Convert error code to human-readable string.
Definition fetch.c:9114

◆ fetch_is_valid_url()

bool fetch_is_valid_url ( const char * url)

Check if a URL is valid.

Parameters
urlURL string to validate
Returns
true if URL is valid
if (fetch_is_valid_url("https://example.com/api")) {
// Safe to use this URL
}
bool fetch_is_valid_url(const char *url)
Check if a URL is valid.
Definition fetch.c:9103

◆ fetch_method_from_string()

http_method_t fetch_method_from_string ( const char * method_str)

Convert string to HTTP method enum.

Parameters
method_strMethod name string (case-insensitive)
Returns
HTTP method enum (defaults to GET for invalid input)
http_method_t method = fetch_method_from_string("post"); // HTTP_METHOD_POST
http_method_t
HTTP request methods.
Definition fetch.h:229
http_method_t fetch_method_from_string(const char *method_str)
Convert string to HTTP method enum.
Definition fetch.c:9077

◆ fetch_method_to_string()

const char * fetch_method_to_string ( http_method_t method)

Convert HTTP method enum to string.

Parameters
methodHTTP method
Returns
Method name string (static, do not free)
Note
Memory: Returned string is static, do not free
printf("Method: %s\n", fetch_method_to_string(HTTP_METHOD_POST)); // "POST"
@ HTTP_METHOD_POST
Definition fetch.h:232
const char * fetch_method_to_string(http_method_t method)
Convert HTTP method enum to string.
Definition fetch.c:9052