C++ API Reference

The tef::RequestHandler class defines an interface to process incoming HTTP requests. An extending class must implement the following methods:

virtual const char* Path() const; Specifies the URL's path of an HTTP request to process.
Example: "/helloworld"
virtual void Process(tef::RequestContext& context) const; Processes the HTTP request.

The tef::RequestContext class wraps an incoming HTTP request.

tef::RequestInput Input; Represents the HTTP request.
tef::RequestOutput Output; Represents the HTTP response.

The tef::RequestInput class represents an HTTP request.

bool IsHttps() const; Indicates whether the HTTP connection uses HTTPS.
const wchar_t* Path() const; Returns the path of the HTTP request.
tef::data operator[](const wchar_t* name) const; Returns a value from the query string or HTML form of the HTTP request.

The tef::RequestOutput class represents an HTTP response.

RequestOutput& operator<<(char data);
RequestOutput& operator<<(int data);
RequestOutput& operator<<(long long data);
RequestOutput& operator<<(double data);
RequestOutput& operator<<(const char* data);
RequestOutput& operator<<(const wchar_t* data);
RequestOutput& operator<<(const tef::error& data);
Appends the data to the HTTP response body.
int Status(); Returns the HTTP status code.
void End(int status = 200); Indicates the end of the HTTP response.

The tef::HttpClient class allows to access other servers via HTTP.

tef::HttpClient::Builder& Url(); Returns the URL string stream.
tef::HttpClient::Builder& Headers(); Returns the HTTP headers stream.
template<typename F>
void SendAsync(F&& callback);
int Send();
Send the HTTP request.
int Status(); Returns the HTTP response status code.
char* ResponseText(); Returns the HTTP response body.

The tef::HttpClient::Builder class allows to construct an HTTP request.

tef::HttpClient::Builder& operator<<(char data);
tef::HttpClient::Builder& operator<<(int data);
tef::HttpClient::Builder& operator<<(long long data);
tef::HttpClient::Builder& operator<<(double data);
tef::HttpClient::Builder& operator<<(const char* data);
tef::HttpClient::Builder& operator<<(const wchar_t* data);
Appends the data to the stream.

Example:

tef::HttpClient http;
http.Url() << L"GET https://server.com/path?uid="  << uid;
http.Headers() << L"If-Match: \"" << _etag << L"\"\r\n";
http.SendAsync([](tef::HttpClient& resp) 
{
    try 
    {
        if( resp.Status() == 200 )
        {
            int charge = resp.ResponseHeaderInt32(L"x-ms-request-charge");
            ...
        }
    } catch(std::exception& e) 
    {
    }
});
        

See Also:

C++ Database API

C++ GPC API

Table of Contents