Providing a custom HTTP implementation for the Vertices SDK
Our header, your implementation
We provide functions signatures in vertices_http.h .
The SDK will call those functions when needed.
Client Init/DeInit
The http_init function is called on Vertices SDK initialization.
/// Init HTTP client/// \param provider Remote API URL, port, specific header and certificate if needed by the client/// \param response_payload_cb Function callback to call when data is ready to be parsed/// \return\cVTC_SUCCESS on success, otherwise error depends on implementationret_code_thttp_init(constprovider_info_t*provider,size_t (*response_payload_cb)(char*chunk,size_t chunk_size));/// Close/deinit the clientvoidhttp_close(void);
The init function is simple: all you have to do is to init the HTTP client using the parameters. The URL, port, specific headers, and certificates are passed with the provider parameter.
The callback function reponse_payload_cb must be kept locally as we will need to call it whenever a response is received after a GET or a POST method call.
The callback
The callback function will be called whenever an HTTP response body is ready to be parsed: a pointer to the received bytes chunk and the size chunk_size will be provided to the Vertices SDK when calling the callback. The buffer can be a pointer allocated by the underlying HTTP client.
GET/POST methods
/// HTTP GET request/// \param provider pointer to provider (url, port..)/// \param relative_path path to append to the provider base URL/// \param headers Headers string, each one must have the format "key:value\n\r"/// \param response_code HTTP response code/// \return error codes:/// - \cVTC_SUCCESS on success/// - \cVTC_ERROR_OFFLINE if offline/// - \cVTC_HTTP_ERROR on HTTP error: check response_code.ret_code_thttp_get(constprovider_info_t*provider,constchar*relative_path,constchar*headers,uint32_t*response_code);/// HTTP POST request/// \param provider pointer to provider (url, port..)/// \param relative_path path to append to the provider base URL/// \param headers Headers string, each one must have the format "key:value\n\r"/// \param body HTTP body/// \param body_size size of \cbody array/// \param response_code HTTP response code/// \return error codes:/// - \cVTC_SUCCESS on success/// - \cVTC_ERROR_OFFLINE if offline/// - \cVTC_HTTP_ERROR on HTTP error: check response_code.ret_code_thttp_post(constprovider_info_t*provider,constchar*relative_path,char*headers,constchar*body,size_t body_size,uint32_t*response_code);