HTTP Client#

This module contains the HTTP Client API functions.

Note

  • Stack overflows may occur if you invoke functions or use your own variables or data structures while handling callbacks. Please configure the stack size by modifying the pre-processor macro SL_SI91X_EVENT_HANDLER_STACK_SIZE as per your application's requirements. See here for the instructions for modifying a pre-processor macro.

  • 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)

Initialize an HTTP client.

sl_status_t
sl_http_client_deinit(sl_http_client_t *client)

Deinitialize an HTTP client and release resources used by 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)

Initialize a callback function for the requested HTTP method.

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

Add extended header with key and value in client request.

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

Delete a specified header field from the extended header based on key of an HTTP client request.

sl_status_t
sl_http_client_delete_all_headers(sl_http_client_request_t *request)

Delete all the headers from the extended header 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)

Send HTTP request.

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

Send an 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)

Initialize an HTTP client.

Parameters
TypeDirectionArgument NameDescription
const sl_http_client_configuration_t *[in]configuration

HTTP client configuration of type sl_http_client_configuration_t

sl_http_client_t *[out]client

sl_http_client_t object which will be initialized with client handle.

Returns


sl_http_client_deinit#

sl_status_t sl_http_client_deinit (sl_http_client_t * client)

Deinitialize an HTTP client and release resources used by HTTP client.

Parameters
TypeDirectionArgument NameDescription
sl_http_client_t *[in]client

HTTP client's handle of type sl_http_client_t

Returns

Note

  • User must call this API to release the resources once the HTTP client is no longer needed. This function deletes extended headers if any exists during deinitialization.


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)

Initialize a callback function for the requested HTTP method.

Parameters
TypeDirectionArgument NameDescription
sl_http_client_request_t *[in]request

HTTP client request configuration of type sl_http_client_request_t

sl_http_client_event_handler_t[in]event_handler

HTTP client callback event handler of type sl_http_client_event_handler_t

void *[in]request_context

User defined context pointer. Memory space for the user defined context must be valid till the response is received.

Returns


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)

Add extended header with key and value in client request.

Parameters
TypeDirectionArgument NameDescription
sl_http_client_request_t *[in]request

HTTP client request configuration of type sl_http_client_request_t

const char *[in]key

Header key.

const char *[in]value

Header value.

Returns

Note

  • If a request does not contain any extended header, this API allocates memory for it.


sl_http_client_delete_header#

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

Delete a specified header field from the extended header based on key of an HTTP client request.

Parameters
TypeDirectionArgument NameDescription
sl_http_client_request_t *[in]request

HTTP client request configuration of type sl_http_client_request_t

const char *[in]key

Header key.

Returns


sl_http_client_delete_all_headers#

sl_status_t sl_http_client_delete_all_headers (sl_http_client_request_t * request)

Delete all the headers from the extended header of an HTTP client request.

Parameters
TypeDirectionArgument NameDescription
sl_http_client_request_t *[in]request

HTTP client request configuration of type sl_http_client_request_t

Returns

Note

  • User must call this API to free the memory allocated to headers.


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)

Send HTTP request.

Parameters
TypeDirectionArgument NameDescription
const sl_http_client_t *[in]client

HTTP client handle of type sl_http_client_t

const sl_http_client_request_t *[in]request

HTTP client request configuration of type sl_http_client_request_t

Returns

Note

    1. HTTP HEAD and DELETE methods are not supported in Si91x specific chipsets.

    2. body_length header in request by default internally in Si91x specific chipsets.

    3. HTTP PUT does not support sending body through this API, it is mandatory to call sl_http_client_write_chunked_data() in Si91x specific chipsets.

    4. HTTP response status and response code e.g., 200, 201, 404, etc will be returned in the corresponding event_handler registered during sl_http_client_request_init().


sl_http_client_write_chunked_data#

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

Send an HTTP POST and PUT chunked data.

Parameters
TypeDirectionArgument NameDescription
const sl_http_client_t *[in]client

HTTP client handle of type sl_http_client_t

uint8_t *[in]data

Buffer pointer of data to be written.

uint32_t[in]data_length

Length of data/chunk to be sent.

bool[in]flush_now

Returns

Note

  • : flush_now feature is not supported in Si91x specific chipsets.