HTTP Server#

This module contains the HTTP Server API functions.

Functions#

sl_status_t
sl_http_server_init(sl_http_server_t *handle, const sl_http_server_config_t *config)

HTTP server initialization function.

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.

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.

sl_status_t
sl_http_server_stop(sl_http_server_t *handle)

Stops the HTTP server thread.

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.

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.

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.

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.

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.

Parameters
[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


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

Parameters
[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

Note

  • After calling this API, the parameter "handle" should not be used in any other API without calling sl_http_server_init() again.


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

Parameters
[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


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

Parameters
[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


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

Parameters
[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


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

Parameters
[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


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

Parameters
[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


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

Parameters
[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


Definition at line 158 of file components/service/sl_http_server/inc/sl_http_server.h