Functions#
This section provides a reference to the HTTP API functions.
Functions#
Initialize an HTTP client.
Denitialize 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 of an HTTP client request.
Delete all the headers from the extended header of an HTTP client request.
Send an HTTP get/post/head/put/delete method based on the selected sl_http_client_method_type_t.
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.
Type | Direction | Argument Name | Description |
---|---|---|---|
const sl_http_client_configuration_t * | [in] | configuration | HTTP client configurations |
sl_http_client_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.
200
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)
Denitialize an HTTP client and release resources used by HTTP client.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_http_client_t * | [in] | client | HTTP client's handle |
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. If there are any extended headers are not deleted, this function deletes them.
215
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 event_handler, void * request_context)
Initialize a callback function for the requested HTTP method.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_http_client_request_t * | [in] | request | HTTP client request configuration. |
sl_http_client_event_handler | [in] | event_handler | HTTP client callback event handler. |
void * | [in] | request_context | User defined context pointer. Memory space for the user defined context must be valid till the response is received. |
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.
232
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.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_http_client_request_t * | [in] | request | HTTP client request configuration. |
const char * | [in] | key | Header key. |
const char * | [in] | value | Header value. |
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.
252
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 of an HTTP client request.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_http_client_request_t * | [in] | request | HTTP client request configuration. |
const char * | [in] | key | Header key. |
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.
266
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.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_http_client_request_t * | [in] | request | HTTP client request configuration. |
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.
280
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 an HTTP get/post/head/put/delete method based on the selected sl_http_client_method_type_t.
Type | Direction | Argument Name | Description |
---|---|---|---|
const sl_http_client_t * | [in] | client | HTTP client handle. |
const sl_http_client_request_t * | [in] | request | HTTP client request configuration. |
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.
Note
Current release does not support HTTP head and delete.
TA adds body_length header in request by default.
SL_HTTP_PUT does not support sending body through this API, it is mandatory to call sl_http_client_write_chunked_data().
298
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.
Type | Direction | Argument Name | Description |
---|---|---|---|
const sl_http_client_t * | [in] | client | HTTP client handle. |
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 | Feature coming soon. |
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.
316
of file components/service/http_client/inc/sl_http_client.h