HTTP Client#

This module contains the HTTP Client API functions.

Note

  • Event/Callback handlers must not contain function calls or code which can block or delay the execution of the event/callback handler as it will cause all the other events to queue up and delay the execution of other events since all the events are invoked and handled from a single thread.

  • Do not call any synchronous SDK APIs from within the Event/Callback handlers.

Functions#

sl_status_t
sl_http_client_init(const sl_http_client_configuration_t *configuration, sl_http_client_t *client)

Initializes an HTTP client.

sl_status_t
sl_http_client_deinit(const sl_http_client_t *client)

Deinitializes an HTTP client and releases resources used by the HTTP client.

sl_status_t
sl_http_client_request_init(sl_http_client_request_t *request, sl_http_client_event_handler_t event_handler, void *request_context)

Initializes a callback function for the specified HTTP request.

sl_status_t
sl_http_client_add_header(sl_http_client_request_t *request, const char *key, const char *value)

Adds an extended header with a key and value to the client request.

sl_status_t
sl_http_client_delete_header(sl_http_client_request_t *request, const char *key)

Deletes a specified header field from the extended headers of an HTTP client request.

sl_status_t
sl_http_client_delete_all_headers(sl_http_client_request_t *request)

Deletes all headers from the extended headers of an HTTP client request.

sl_status_t
sl_http_client_send_request(const sl_http_client_t *client, const sl_http_client_request_t *request)

Sends an HTTP request.

sl_status_t
sl_http_client_write_chunked_data(const sl_http_client_t *client, const uint8_t *data, uint32_t data_length, bool flush_now)

Sends HTTP POST and PUT chunked data.

Function Documentation#

sl_http_client_init#

sl_status_t sl_http_client_init (const sl_http_client_configuration_t * configuration, sl_http_client_t * client)

Initializes an HTTP client.

Parameters
[in]configuration

Pointer to an sl_http_client_configuration_t structure containing the configuration settings for the HTTP client. Must not be NULL.

[out]client

Pointer to an sl_http_client_t object that would be initialized with the client handle. Must not be NULL.

It prepares the client to send HTTP requests. You should call this function before making any HTTP requests to ensure the client is properly configured.

Note

    • You can call this function multiple times to initialize multiple HTTP client resources.

    • You can use this function after calling deinit() to reinitialize the resource.

Returns


Definition at line 329 of file components/service/http_client/inc/sl_http_client.h

sl_http_client_deinit#

sl_status_t sl_http_client_deinit (const sl_http_client_t * client)

Deinitializes an HTTP client and releases resources used by the HTTP client.

Parameters
[in]client

Pointer to an sl_http_client_t object representing the HTTP client handle. Must not be NULL.

This function deinitializes the HTTP client, freeing any resources that were allocated during its initialization and usage. It also deletes any extended headers that may exist.

Returns

Note

  • The user must call this function to release resources once the HTTP client is no longer needed.


Definition at line 355 of file components/service/http_client/inc/sl_http_client.h

sl_http_client_request_init#

sl_status_t sl_http_client_request_init (sl_http_client_request_t * request, sl_http_client_event_handler_t event_handler, void * request_context)

Initializes a callback function for the specified HTTP request.

Parameters
[in]request

Pointer to an sl_http_client_request_t structure containing the HTTP client request configuration. Must not be NULL.

[in]event_handler

Callback function of type sl_http_client_event_handler_t to handle HTTP client events. Must not be NULL.

[in]request_context

User-defined context pointer. The memory space for this context must remain valid until the response is received.

This function sets up a callback function to handle events for a specific HTTP request. It must be called after initializing the HTTP client.

Returns


Definition at line 383 of file components/service/http_client/inc/sl_http_client.h

sl_http_client_add_header#

sl_status_t sl_http_client_add_header (sl_http_client_request_t * request, const char * key, const char * value)

Adds an extended header with a key and value to the client request.

Parameters
[in]request

Pointer to an sl_http_client_request_t structure representing the HTTP client request configuration. Must not be NULL.

[in]key

Pointer to a string containing the header key. Must not be NULL.

[in]value

Pointer to a string containing the header value. Must not be NULL.

This function adds an extended header to the specified HTTP client request. If the request does not already contain any extended headers, this function allocates memory for them.

Returns

Note

  • If the request does not contain any extended headers, this function allocates memory for them.


Definition at line 417 of file components/service/http_client/inc/sl_http_client.h

sl_http_client_delete_header#

sl_status_t sl_http_client_delete_header (sl_http_client_request_t * request, const char * key)

Deletes a specified header field from the extended headers of an HTTP client request.

Parameters
[in]request

Pointer to an sl_http_client_request_t structure represents the HTTP client request configuration. Must not be NULL.

[in]key

Pointer to a string contains the header key to be deleted. Must not be NULL.

This function removes a header field from the extended headers of the specified HTTP client request based on the provided key.

Returns


Definition at line 442 of file components/service/http_client/inc/sl_http_client.h

sl_http_client_delete_all_headers#

sl_status_t sl_http_client_delete_all_headers (sl_http_client_request_t * request)

Deletes all headers from the extended headers of an HTTP client request.

Parameters
[in]request

Pointer to an sl_http_client_request_t structure representing the HTTP client request configuration. Must not be NULL.

This function removes all headers from the extended headers of the specified HTTP client request. It frees up the memory allocated for these headers.

Returns

Note

  • The user must call this function to free the memory allocated for the headers.


Definition at line 467 of file components/service/http_client/inc/sl_http_client.h

sl_http_client_send_request#

sl_status_t sl_http_client_send_request (const sl_http_client_t * client, const sl_http_client_request_t * request)

Sends an HTTP request.

Parameters
[in]client

Pointer to an sl_http_client_t object representing the HTTP client handle. Must not be NULL.

[in]request

Pointer to an sl_http_client_request_t object representing the HTTP client request configuration. Must not be NULL.

This function sends an HTTP request using the specified client and request configuration. It must be called after initializing the request with sl_http_client_request_init.

Returns

Note

    • HTTP HEAD and DELETE methods are not supported on Si91x specific chipsets.

    • The body_length header in the request is set internally by default on Si91x specific chipsets.

    • HTTP PUT does not support sending the body through this API; it is mandatory to call sl_http_client_write_chunked_data on Si91x specific chipsets.

    • HTTP response status and response codes (e.g., 200, 201, 404) would be returned in the corresponding event handler registered during sl_http_client_request_init.


Definition at line 499 of file components/service/http_client/inc/sl_http_client.h

sl_http_client_write_chunked_data#

sl_status_t sl_http_client_write_chunked_data (const sl_http_client_t * client, const uint8_t * data, uint32_t data_length, bool flush_now)

Sends HTTP POST and PUT chunked data.

Parameters
[in]client

Pointer to an sl_http_client_t object representing the HTTP client handle. Must not be NULL.

[in]data

Pointer to the buffer containing the data to be written. Must not be NULL.

[in]data_length

Length of the data chunk to be sent.

[in]flush_now

Boolean flag indicating whether to flush the data immediately. Note that this feature is not supported on Si91x specific chipsets.

This function sends a chunk of data as part of an HTTP POST or PUT request. It should be used after initiating the request with sl_http_client_send_request. The data can be sent in multiple chunks by calling this function multiple times.

Returns

Note

  • The flush_now feature is not supported on Si91x specific chipsets.


Definition at line 534 of file components/service/http_client/inc/sl_http_client.h