Nigel Rantor / azure_c_shared_utility

Fork of azure_c_shared_utility by Azure IoT

Embed: (wiki syntax)

« Back to documentation index

httpapi.h File Reference

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:
handleThe handle to the HTTP connection created via HTTPAPI_CreateConnection.
optionNameA NULL terminated string representing the name of the option.
valueA 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:
handleThe handle to the HTTP connection created via HTTPAPI_CreateConnection.
requestTypeSpecifies which HTTP method is used (GET, POST, DELETE, PUT, PATCH).
relativePathSpecifies the relative path of the URL excluding the host name.
httpHeadersHandleSpecifies 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 in HTTPHeaders.h.
contentSpecifies a pointer to the request body. This value is optional and can be NULL.
contentLengthSpecifies 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.
statusCodeThis is an out parameter, where HTTPAPI_ExecuteRequest returns the status code from the HTTP response (200, 201, 400, 401, etc.)
responseHeadersHandleThis 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 in HTTPHeaders.h
responseContentThis 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 in Strings.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:
handleThe 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:
hostNameName 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 or NULL 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:
optionNameA NULL terminated string representing the name of the option
valueA pointer to the value of the option.
savedValueThis 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.