Skip to main content

HTTP

ULC comes with get and post functionality facilitated by openssl. This can be used to communicate with API's or other networked services. This is generally limited to RESTful API's or http servers/clients.

info

All get and post methods from ULC are routed via these functions.

Sending a get request

To send a get request do the following:

#include "ULC.hpp"
#include <string>
#include <map>

using namespace ULC;
using namespace ULC::HTTP;

UL_HTTP http{}

// For cerification you can provide a path
http.SetCertPath("cacert.pem");

std::string response;
http.Get("url_to_get_from", response);

// There are optional paramaters for timeout, headers, and floags, these are like options for UL_Node and UL_BlockchainManagement
long timeoutSeconds = UL_DEFAULT_HTTP_REQUEST_TIMEOUT;
std::map<std::string, std::string> headers{};
UL_Debug_Flags flags{}; // This is the flags used for http calls, that are inside UL_Options. Use this for verbose logs, etc.
http.Get("url_to_get_from", response, timeoutSeconds, headers, flags);

Sending a post request

To send a post request do the following:

#include "ULC.hpp"
#include <string>
#include <map>

using namespace ULC;
using namespace ULC::HTTP;

UL_HTTP http{}

// For cerification you can provide a path
http.SetCertPath("cacert.pem");

std::string body = "my_body_to_post";
std::string response;
http.Post("url_to_post_to", body, response);

// There are optional paramaters for timeout, headers, and floags, these are like options for UL_Node and UL_BlockchainManagement
long timeoutSeconds = UL_DEFAULT_HTTP_REQUEST_TIMEOUT;
std::map<std::string, std::string> headers{};
UL_Debug_Flags flags{}; // This is the flags used for http calls, that are inside UL_Options. Use this for verbose logs, etc.
http.Post("url_to_post_to", body, response, timeout, headers, flags);
© 2023 ULedger Inc. All rights reserved