HTTP Server#
This module contains the HTTP Server API functions.
Functions#
HTTP server initialization function.
Deinitializes the HTTP server and frees all the resources related to the HTTP server handle.
Spawns a new thread and starts accepting requests on the configured HTTP port.
Stops the HTTP server thread.
Retrieves the headers from an HTTP request.
Reads the HTTP request data being received after the headers.
Makes the HTTP server send the response to the current request.
HTTP server data writing function.
Function Documentation#
sl_http_server_init#
sl_status_t sl_http_server_init (sl_http_server_t * handle, const sl_http_server_config_t * config)
HTTP server initialization function.
[out] | handle | sl_http_server_t object which will be initialized with the server handle. |
[in] | config | HTTP server configuration of type sl_http_server_config_t. |
This function initializes an HTTP server by taking in the configuration structure and the pointer to the HTTP server handle. All the APIs must be used only after this API using the HTTP server handle returned in the "handle" parameter.
Returns
sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details.
50
of file components/service/sl_http_server/inc/sl_http_server.h
sl_http_server_deinit#
sl_status_t sl_http_server_deinit (sl_http_server_t * handle)
Deinitializes the HTTP server and frees all the resources related to the HTTP server handle.
[in] | handle | HTTP server handle of type sl_http_server_t |
Pre-conditions:
The HTTP server handle should be initialized using sl_http_server_init before calling this API.
Returns
sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details.
Note
After calling this API, the parameter "handle" should not be used in any other API without calling sl_http_server_init() again.
64
of file components/service/sl_http_server/inc/sl_http_server.h
sl_http_server_start#
sl_status_t sl_http_server_start (sl_http_server_t * handle)
Spawns a new thread and starts accepting requests on the configured HTTP port.
[in] | handle | HTTP server handle of type sl_http_server_t |
The HTTP request handlers are invoked from this thread.
Pre-conditions:
The HTTP server handle should be initialized using sl_http_server_init before calling this API.
Returns
sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details.
77
of file components/service/sl_http_server/inc/sl_http_server.h
sl_http_server_stop#
sl_status_t sl_http_server_stop (sl_http_server_t * handle)
Stops the HTTP server thread.
[in] | handle | HTTP server handle of type sl_http_server_t |
Pre-conditions:
The HTTP server handle should be initialized using sl_http_server_init before calling this API.
Returns
sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details.
89
of file components/service/sl_http_server/inc/sl_http_server.h
sl_http_server_get_request_headers#
sl_status_t sl_http_server_get_request_headers (sl_http_server_t * handle, sl_http_server_request_t * request, sl_http_header_t * headers, uint16_t header_count)
Retrieves the headers from an HTTP request.
[in] | handle | HTTP server handle of type sl_http_server_t. |
[in] | request | HTTP request from which headers are to be retrieved of type sl_http_server_request_t. |
[out] | headers | Array where the retrieved headers will be stored of type sl_http_header_t. |
[in] | header_count | Number of headers that the array can hold. |
This function extracts all headers from a given HTTP request and stores them in the provided headers array. Returns
sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details.
107
of file components/service/sl_http_server/inc/sl_http_server.h
sl_http_server_read_request_data#
sl_status_t sl_http_server_read_request_data (sl_http_server_t * handle, sl_http_recv_req_data_t * data)
Reads the HTTP request data being received after the headers.
[in] | handle | HTTP server handle of type sl_http_server_t |
[in] | data | Pointer to the receive parameters structure of type sl_http_recv_req_data_t |
Pre-conditions:
This API can only be called if req_data_length parameter in sl_http_server_request_t is greater than 0.
This API can only be called from with in the request handler of corresponding request.
Returns
sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details.
125
of file components/service/sl_http_server/inc/sl_http_server.h
sl_http_server_send_response#
sl_status_t sl_http_server_send_response (sl_http_server_t * handle, sl_http_server_response_t * response)
Makes the HTTP server send the response to the current request.
[in] | handle | HTTP server handle of type sl_http_server_t |
[in] | response | Pointer to the response of type sl_http_server_response_t |
This API can only be called once per request.
Pre-conditions:
The HTTP server handle should be initialized using sl_http_server_init before calling this API.
Returns
sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details.
140
of file components/service/sl_http_server/inc/sl_http_server.h
sl_http_server_write_data#
sl_status_t sl_http_server_write_data (sl_http_server_t * handle, uint8_t * data, uint32_t data_length)
HTTP server data writing function.
[in] | handle | HTTP server handle of type sl_http_server_t. |
[in] | data | Pointer to the data to be sent. |
[in] | data_length | Length of the data to be sent. |
This function sends a chunk of data as part of the HTTP response. It should be used after a response has been started with sl_http_server_send_response, and can be called multiple times to send the response data in chunks.
Returns
sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details.
158
of file components/service/sl_http_server/inc/sl_http_server.h