Functions#

This section provides a reference to the HTTP API functions.

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)

Denitialize 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 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 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 an HTTP get/post/head/put/delete method based on the selected sl_http_client_method_type_t.

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
[in]configuration

HTTP client configurations

[out]client

sl_http_client_t object which will be initialized with client handle

Returns


Definition at line 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.

Parameters
[in]client

HTTP client's handle

Returns

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.


Definition at line 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.

Parameters
[in]request

HTTP client request configuration.

[in]event_handler

HTTP client callback event handler.

[in]request_context

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

Returns


Definition at line 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.

Parameters
[in]request

HTTP client request configuration.

[in]key

Header key.

[in]value

Header value.

Returns

Note

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


Definition at line 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.

Parameters
[in]request

HTTP client request configuration.

[in]key

Header key.

Returns


Definition at line 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.

Parameters
[in]request

HTTP client request configuration.

Returns

Note

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


Definition at line 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.

Parameters
[in]client

HTTP client handle.

[in]request

HTTP client request configuration.

Returns

Note

    1. Current release does not support HTTP head and delete.

    2. TA adds body_length header in request by default.

    3. SL_HTTP_PUT does not support sending body through this API, it is mandatory to call sl_http_client_write_chunked_data().


Definition at line 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.

Parameters
[in]client

HTTP client handle.

[in]data

Buffer pointer of data to be written.

[in]data_length

Length of data/chunk to be sent.

[in]flush_now

Feature coming soon.

Returns


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