Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface NTPClient iothub_amqp_transport iothub_client mbed-rtos mbed
Fork of iothub_client_sample_amqp by
httpapi.h File Reference
This module implements the standard HTTP API used by the C IoT client library. More...
Go to the source code of this file.
Functions | |
DEFINE_ENUM (HTTPAPI_RESULT, HTTPAPI_RESULT_VALUES) | |
Enumeration specifying the possible return values for the APIs in this module. | |
DEFINE_ENUM (HTTPAPI_REQUEST_TYPE, HTTPAPI_REQUEST_TYPE_VALUES) | |
Enumeration specifying the HTTP request verbs accepted by the HTTPAPI module. | |
MOCKABLE_FUNCTION (, HTTPAPI_RESULT, HTTPAPI_Init) | |
Global initialization for the HTTP API component. | |
MOCKABLE_FUNCTION (, void, HTTPAPI_Deinit) | |
Free resources allocated in HTTPAPI_Init. | |
MOCKABLE_FUNCTION (, HTTP_HANDLE, HTTPAPI_CreateConnection, const char *, hostName) | |
Creates an HTTPS connection to the host specified by the hostName parameter. | |
MOCKABLE_FUNCTION (, void, HTTPAPI_CloseConnection, HTTP_HANDLE, handle) | |
Closes a connection created with HTTPAPI_CreateConnection. | |
MOCKABLE_FUNCTION (, HTTPAPI_RESULT, HTTPAPI_ExecuteRequest, HTTP_HANDLE, handle, HTTPAPI_REQUEST_TYPE, requestType, const char *, relativePath, HTTP_HEADERS_HANDLE, httpHeadersHandle, const unsigned char *, content, size_t, contentLength, unsigned int *, statusCode, HTTP_HEADERS_HANDLE, responseHeadersHandle, BUFFER_HANDLE, responseContent) | |
Sends the HTTP request to the host and handles the response for the HTTP call. | |
MOCKABLE_FUNCTION (, HTTPAPI_RESULT, HTTPAPI_SetOption, HTTP_HANDLE, handle, const char *, optionName, const void *, value) | |
Sets the option named optionName bearing the value value for the HTTP_HANDLE handle . | |
MOCKABLE_FUNCTION (, HTTPAPI_RESULT, HTTPAPI_CloneOption, const char *, optionName, const void *, value, const void **, savedValue) | |
Clones the option named optionName bearing the value value into the pointer savedValue . |
Detailed Description
This module implements the standard HTTP API used by the C IoT client library.
For example, on the Windows platform the HTTP API code uses WinHTTP and for Linux it uses curl and so forth. HTTPAPI must support HTTPs (HTTP+SSL).
Definition in file httpapi.h.
Function Documentation
DEFINE_ENUM | ( | HTTPAPI_RESULT | , |
HTTPAPI_RESULT_VALUES | |||
) |
Enumeration specifying the possible return values for the APIs in this module.
DEFINE_ENUM | ( | HTTPAPI_REQUEST_TYPE | , |
HTTPAPI_REQUEST_TYPE_VALUES | |||
) |
Enumeration specifying the HTTP request verbs accepted by the HTTPAPI module.
MOCKABLE_FUNCTION | ( | HTTPAPI_RESULT | , |
HTTPAPI_SetOption | , | ||
HTTP_HANDLE | , | ||
handle | , | ||
const char * | , | ||
optionName | , | ||
const void * | , | ||
value | |||
) |
Sets the option named optionName
bearing the value value
for the HTTP_HANDLE handle
.
- Parameters:
-
handle The handle to the HTTP connection created via HTTPAPI_CreateConnection. optionName A NULL
terminated string representing the name of the option.value A pointer to the value for the option.
- Returns:
HTTPAPI_OK
if initialization is successful or an error code in case it fails.
MOCKABLE_FUNCTION | ( | HTTPAPI_RESULT | , |
HTTPAPI_ExecuteRequest | , | ||
HTTP_HANDLE | , | ||
handle | , | ||
HTTPAPI_REQUEST_TYPE | , | ||
requestType | , | ||
const char * | , | ||
relativePath | , | ||
HTTP_HEADERS_HANDLE | , | ||
httpHeadersHandle | , | ||
const unsigned char * | , | ||
content | , | ||
size_t | , | ||
contentLength | , | ||
unsigned int * | , | ||
statusCode | , | ||
HTTP_HEADERS_HANDLE | , | ||
responseHeadersHandle | , | ||
BUFFER_HANDLE | , | ||
responseContent | |||
) |
Sends the HTTP request to the host and handles the response for the HTTP call.
- Parameters:
-
handle The handle to the HTTP connection created via HTTPAPI_CreateConnection. requestType Specifies which HTTP method is used (GET, POST, DELETE, PUT, PATCH). relativePath Specifies the relative path of the URL excluding the host name. httpHeadersHandle Specifies a set of HTTP headers (name-value pairs) to be added to the HTTP request. The httpHeadersHandle
handle can be created and setup with the proper name-value pairs by using the HTTPHeaders APIs available inHTTPHeaders.h
.content Specifies a pointer to the request body. This value is optional and can be NULL
.contentLength Specifies the request body size (this is typically added into the HTTP headers as the Content-Length header). This value is optional and can be 0. statusCode This is an out parameter, where HTTPAPI_ExecuteRequest returns the status code from the HTTP response (200, 201, 400, 401, etc.) responseHeadersHandle This is an HTTP headers handle to which HTTPAPI_ExecuteRequest must add all the HTTP response headers so that the caller of HTTPAPI_ExecuteRequest can inspect them. You can manipulate responseHeadersHandle
by using the HTTPHeaders APIs available inHTTPHeaders.h
responseContent This is a buffer that must be filled by HTTPAPI_ExecuteRequest with the contents of the HTTP response body. The buffer size must be increased by the HTTPAPI_ExecuteRequest implementation in order to fit the response body. HTTPAPI_ExecuteRequest must also handle chunked transfer encoding for HTTP responses. To manipulate the responseContent
buffer, use the APIs available inStrings.h
.
- Returns:
HTTPAPI_OK
if the API call is successful or an error code in case it fails.
MOCKABLE_FUNCTION | ( | void | , |
HTTPAPI_CloseConnection | , | ||
HTTP_HANDLE | , | ||
handle | |||
) |
Closes a connection created with HTTPAPI_CreateConnection.
- Parameters:
-
handle The handle to the HTTP connection created via HTTPAPI_CreateConnection.
All resources allocated by HTTPAPI_CreateConnection should be freed in HTTPAPI_CloseConnection.
MOCKABLE_FUNCTION | ( | HTTP_HANDLE | , |
HTTPAPI_CreateConnection | , | ||
const char * | , | ||
hostName | |||
) |
Creates an HTTPS connection to the host specified by the hostName
parameter.
- Parameters:
-
hostName Name of the host.
This function returns a handle to the newly created connection. You can use the handle in subsequent calls to execute specific HTTP calls using HTTPAPI_ExecuteRequest.
- Returns:
- A
HTTP_HANDLE
to the newly created connection orNULL
in case an error occurs.
MOCKABLE_FUNCTION | ( | void | , |
HTTPAPI_Deinit | |||
) |
Free resources allocated in HTTPAPI_Init.
MOCKABLE_FUNCTION | ( | HTTPAPI_RESULT | , |
HTTPAPI_Init | |||
) |
Global initialization for the HTTP API component.
Platform specific implementations are expected to initialize the underlying HTTP API stacks.
- Returns:
HTTPAPI_OK
if initialization is successful or an error code in case it fails.
MOCKABLE_FUNCTION | ( | HTTPAPI_RESULT | , |
HTTPAPI_CloneOption | , | ||
const char * | , | ||
optionName | , | ||
const void * | , | ||
value | , | ||
const void ** | , | ||
savedValue | |||
) |
Clones the option named optionName
bearing the value value
into the pointer savedValue
.
- Parameters:
-
optionName A NULL
terminated string representing the name of the optionvalue A pointer to the value of the option. savedValue This pointer receives the copy of the value of the option. The copy needs to be free-able.
- Returns:
HTTPAPI_OK
if initialization is successful or an error code in case it fails.
Generated on Tue Jul 12 2022 12:43:26 by
