oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
Data Structures | Enumerations | Functions
HTTP Client

Portable HTTP/1.1 client for REST APIs. More...

Data Structures

struct  ove_http_header_t
 HTTP request header (name-value pair). More...
 
struct  ove_http_response_t
 HTTP response (returned by request functions). More...
 

Enumerations

enum  ove_http_method_t {
  OVE_HTTP_GET = 0 , OVE_HTTP_POST = 1 , OVE_HTTP_PUT = 2 , OVE_HTTP_DELETE = 3 ,
  OVE_HTTP_PATCH = 4
}
 HTTP method. More...
 

Functions

int ove_http_client_init (ove_http_client_t *client, ove_http_client_storage_t *storage)
 Initialise an HTTP client from caller-supplied storage.
 
void ove_http_client_deinit (ove_http_client_t client)
 De-initialise an HTTP client.
 
int ove_http_get (ove_http_client_t client, const char *url, ove_http_response_t *resp)
 Perform an HTTP GET request.
 
int ove_http_post (ove_http_client_t client, const char *url, const char *content_type, const void *body, size_t body_len, ove_http_response_t *resp)
 Perform an HTTP POST request.
 
int ove_http_request (ove_http_client_t client, ove_http_method_t method, const char *url, const char *content_type, const void *body, size_t body_len, ove_http_response_t *resp)
 Perform a generic HTTP request.
 
int ove_http_request_ex (ove_http_client_t client, ove_http_method_t method, const char *url, const char *content_type, const void *body, size_t body_len, const ove_http_header_t *headers, size_t header_count, ove_http_response_t *resp)
 Perform an HTTP request with custom headers.
 
void ove_http_response_free (ove_http_response_t *resp)
 Free resources in an HTTP response.
 
int ove_http_client_create (ove_http_client_t *client)
 Heap-allocate and initialise an HTTP client.
 
void ove_http_client_destroy (ove_http_client_t client)
 Destroy a heap-allocated HTTP client.
 

Detailed Description

Portable HTTP/1.1 client for REST APIs.

Supports GET and POST with optional TLS (when OVE_NET_TLS is enabled). The client is portable C and delegates I/O to the socket/TLS layers.

Note
Requires CONFIG_OVE_NET_HTTP (implies CONFIG_OVE_NET). When disabled every function is replaced by a no-op stub.

Enumeration Type Documentation

◆ ove_http_method_t

HTTP method.

Enumerator
OVE_HTTP_GET 

HTTP GET.

OVE_HTTP_POST 

HTTP POST.

OVE_HTTP_PUT 

HTTP PUT.

OVE_HTTP_DELETE 

HTTP DELETE.

OVE_HTTP_PATCH 

HTTP PATCH.

Function Documentation

◆ ove_http_client_init()

int ove_http_client_init ( ove_http_client_t client,
ove_http_client_storage_t *  storage 
)

Initialise an HTTP client from caller-supplied storage.

Parameters
[out]clientHandle written on success.
[in]storageCaller-allocated storage.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_http_client_deinit()

void ove_http_client_deinit ( ove_http_client_t  client)

De-initialise an HTTP client.

Parameters
[in]clientHandle returned by ove_http_client_init().

◆ ove_http_get()

int ove_http_get ( ove_http_client_t  client,
const char *  url,
ove_http_response_t resp 
)

Perform an HTTP GET request.

Parameters
[in]clientHTTP client handle.
[in]urlFull URL (e.g. "http://example.com/path").
[out]respResponse filled on success.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_http_post()

int ove_http_post ( ove_http_client_t  client,
const char *  url,
const char *  content_type,
const void *  body,
size_t  body_len,
ove_http_response_t resp 
)

Perform an HTTP POST request.

Parameters
[in]clientHTTP client handle.
[in]urlFull URL.
[in]content_typeContent-Type header value (e.g. "application/json").
[in]bodyRequest body data.
[in]body_lenRequest body length in bytes.
[out]respResponse filled on success.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_http_request()

int ove_http_request ( ove_http_client_t  client,
ove_http_method_t  method,
const char *  url,
const char *  content_type,
const void *  body,
size_t  body_len,
ove_http_response_t resp 
)

Perform a generic HTTP request.

Parameters
[in]clientHTTP client handle.
[in]methodHTTP method.
[in]urlFull URL.
[in]content_typeContent-Type (may be NULL for GET).
[in]bodyRequest body (may be NULL).
[in]body_lenRequest body length.
[out]respResponse filled on success.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_http_request_ex()

int ove_http_request_ex ( ove_http_client_t  client,
ove_http_method_t  method,
const char *  url,
const char *  content_type,
const void *  body,
size_t  body_len,
const ove_http_header_t headers,
size_t  header_count,
ove_http_response_t resp 
)

Perform an HTTP request with custom headers.

Parameters
[in]clientHTTP client handle.
[in]methodHTTP method (GET, POST, PUT, DELETE, PATCH).
[in]urlFull URL.
[in]content_typeContent-Type (may be NULL).
[in]bodyRequest body (may be NULL).
[in]body_lenRequest body length.
[in]headersArray of extra request headers (may be NULL).
[in]header_countNumber of headers in the array.
[out]respResponse filled on success.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_http_response_free()

void ove_http_response_free ( ove_http_response_t resp)

Free resources in an HTTP response.

Parameters
[in]respResponse to free (body and headers are freed).

◆ ove_http_client_create()

int ove_http_client_create ( ove_http_client_t client)

Heap-allocate and initialise an HTTP client.

Parameters
[out]clientHandle written on success.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_http_client_destroy()

void ove_http_client_destroy ( ove_http_client_t  client)

Destroy a heap-allocated HTTP client.

Parameters
[in]clientHandle returned by ove_http_client_create().