HTTP Client#
This module contains the HTTP Client API functions.
Functions#
Initialize an HTTP client.
Deinitialize an HTTP client and release resources used by HTTP client.
Initialize a callback function for the requested HTTP method.
Add extended header with key and value in client request.
Delete a specified header field from the extended header based on key of an HTTP client request.
Delete all the headers from the extended header of an HTTP client request.
Send HTTP request.
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.
[in] | configuration | HTTP client configuration of type sl_http_client_configuration_t |
[out] | client | sl_http_client_t object which will be initialized with client handle. |
Returns
sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details.
212
of file components/service/http_client/inc/sl_http_client.h
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.
[in] | client | HTTP client's handle of type sl_http_client_t |
Pre-conditions:
sl_http_client_init should be called before this API.
Returns
sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details.
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.
228
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)
Initialize a callback function for the requested HTTP method.
[in] | request | HTTP client request configuration of type sl_http_client_request_t |
[in] | event_handler | HTTP client callback event handler of type sl_http_client_event_handler_t |
[in] | request_context | User defined context pointer. Memory space for the user defined context must be valid till the response is received. |
Pre-conditions:
sl_http_client_init should be called before this API.
Returns
sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details.
246
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)
Add extended header with key and value in client request.
[in] | request | HTTP client request configuration of type sl_http_client_request_t |
[in] | key | Header key. |
[in] | value | Header value. |
Pre-conditions:
sl_http_client_init should be called before this API.
Returns
sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details.
Note
If a request does not contain any extended header, this API allocates memory for it.
267
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)
Delete a specified header field from the extended header based on key of an HTTP client request.
[in] | request | HTTP client request configuration of type sl_http_client_request_t |
[in] | key | Header key. |
Pre-conditions:
sl_http_client_add_header should be called before this API.
Returns
sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details.
282
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)
Delete all the headers from the extended header of an HTTP client request.
[in] | request | HTTP client request configuration of type sl_http_client_request_t |
Pre-conditions:
sl_http_client_add_header should be called before this API.
Returns
sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details.
Note
User must call this API to free the memory allocated to headers.
297
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)
Send HTTP request.
[in] | client | HTTP client handle of type sl_http_client_t |
[in] | request | HTTP client request configuration of type sl_http_client_request_t |
Pre-conditions:
sl_http_client_request_init should be called before this API.
Returns
sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. This status only indicates the library status.
Note
HTTP HEAD and DELETE methods are not supported in Si91x specific chipsets.
body_length header in request by default internally in Si91x specific chipsets.
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.
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().
318
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, uint8_t * data, uint32_t data_length, bool flush_now)
Send an HTTP POST and PUT chunked data.
[in] | client | HTTP client handle of type sl_http_client_t |
[in] | data | Buffer pointer of data to be written. |
[in] | data_length | Length of data/chunk to be sent. |
[in] | flush_now |
Pre-conditions:
sl_http_client_send_request should be called before this API.
Returns
sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details.
Note
: flush_now feature is not supported in Si91x specific chipsets.
338
of file components/service/http_client/inc/sl_http_client.h