C++ Rest SDK
The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Public Member Functions | List of all members
web::http::client::http_client Class Reference

HTTP client class, used to maintain a connection to an HTTP service for an extended session. More...

#include <http_client.h>

Public Member Functions

_ASYNCRTIMP http_client (const uri &base_uri)
 Creates a new http_client connected to specified uri. More...
 
_ASYNCRTIMP http_client (const uri &base_uri, const http_client_config &client_config)
 Creates a new http_client connected to specified uri. More...
 
 ~http_client () CPPREST_NOEXCEPT
 Note the destructor doesn't necessarily close the connection and release resources. The connection is reference counted with the http_responses. More...
 
_ASYNCRTIMP const uribase_uri () const
 Gets the base URI. More...
 
_ASYNCRTIMP const http_client_configclient_config () const
 Get client configuration object More...
 
void add_handler (const std::function< pplx::task< http_response >(http_request, std::shared_ptr< http::http_pipeline_stage >)> &handler)
 Adds an HTTP pipeline stage to the client. More...
 
void add_handler (const std::shared_ptr< http::http_pipeline_stage > &stage)
 Adds an HTTP pipeline stage to the client. More...
 
_ASYNCRTIMP pplx::task< http_responserequest (http_request request, const pplx::cancellation_token &token=pplx::cancellation_token::none())
 Asynchronously sends an HTTP request. More...
 
pplx::task< http_responserequest (const method &mtd, const pplx::cancellation_token &token=pplx::cancellation_token::none())
 Asynchronously sends an HTTP request. More...
 
pplx::task< http_responserequest (const method &mtd, const utility::string_t &path_query_fragment, const pplx::cancellation_token &token=pplx::cancellation_token::none())
 Asynchronously sends an HTTP request. More...
 
pplx::task< http_responserequest (const method &mtd, const utility::string_t &path_query_fragment, const json::value &body_data, const pplx::cancellation_token &token=pplx::cancellation_token::none())
 Asynchronously sends an HTTP request. More...
 
pplx::task< http_responserequest (const method &mtd, const utf8string &path_query_fragment, const utf8string &body_data, const utf8string &content_type="text/plain; charset=utf-8", const pplx::cancellation_token &token=pplx::cancellation_token::none())
 Asynchronously sends an HTTP request with a string body. Assumes the character encoding of the string is UTF-8. More...
 
pplx::task< http_responserequest (const method &mtd, const utf8string &path_query_fragment, utf8string &&body_data, const utf8string &content_type="text/plain; charset=utf-8", const pplx::cancellation_token &token=pplx::cancellation_token::none())
 Asynchronously sends an HTTP request with a string body. Assumes the character encoding of the string is UTF-8. More...
 
pplx::task< http_responserequest (const method &mtd, const utf16string &path_query_fragment, const utf16string &body_data, const utf16string &content_type=::utility::conversions::to_utf16string("text/plain"), const pplx::cancellation_token &token=pplx::cancellation_token::none())
 Asynchronously sends an HTTP request with a string body. Assumes the character encoding of the string is UTF-16 will perform conversion to UTF-8. More...
 
pplx::task< http_responserequest (const method &mtd, const utf8string &path_query_fragment, const utf8string &body_data, const pplx::cancellation_token &token)
 Asynchronously sends an HTTP request with a string body. Assumes the character encoding of the string is UTF-8. More...
 
pplx::task< http_responserequest (const method &mtd, const utf8string &path_query_fragment, utf8string &&body_data, const pplx::cancellation_token &token)
 Asynchronously sends an HTTP request with a string body. Assumes the character encoding of the string is UTF-8. More...
 
pplx::task< http_responserequest (const method &mtd, const utf16string &path_query_fragment, const utf16string &body_data, const pplx::cancellation_token &token)
 Asynchronously sends an HTTP request with a string body. Assumes the character encoding of the string is UTF-16 will perform conversion to UTF-8. More...
 
pplx::task< http_responserequest (const method &mtd, const utility::string_t &path_query_fragment, const concurrency::streams::istream &body, const utility::string_t &content_type=_XPLATSTR("application/octet-stream"), const pplx::cancellation_token &token=pplx::cancellation_token::none())
 Asynchronously sends an HTTP request. More...
 
pplx::task< http_responserequest (const method &mtd, const utility::string_t &path_query_fragment, const concurrency::streams::istream &body, const pplx::cancellation_token &token)
 Asynchronously sends an HTTP request. More...
 
pplx::task< http_responserequest (const method &mtd, const utility::string_t &path_query_fragment, const concurrency::streams::istream &body, size_t content_length, const utility::string_t &content_type=_XPLATSTR("application/octet-stream"), const pplx::cancellation_token &token=pplx::cancellation_token::none())
 Asynchronously sends an HTTP request. More...
 
pplx::task< http_responserequest (const method &mtd, const utility::string_t &path_query_fragment, const concurrency::streams::istream &body, size_t content_length, const pplx::cancellation_token &token)
 Asynchronously sends an HTTP request. More...
 

Detailed Description

HTTP client class, used to maintain a connection to an HTTP service for an extended session.

Constructor & Destructor Documentation

web::http::client::http_client::http_client ( const uri base_uri)

Creates a new http_client connected to specified uri.

Parameters
base_uriA string representation of the base uri to be used for all requests. Must start with either "http://" or "https://"
web::http::client::http_client::http_client ( const uri base_uri,
const http_client_config client_config 
)

Creates a new http_client connected to specified uri.

Parameters
base_uriA string representation of the base uri to be used for all requests. Must start with either "http://" or "https://"
client_configThe http client configuration object containing the possible configuration options to initialize the http_client.
web::http::client::http_client::~http_client ( )
inline

Note the destructor doesn't necessarily close the connection and release resources. The connection is reference counted with the http_responses.

Member Function Documentation

void web::http::client::http_client::add_handler ( const std::function< pplx::task< http_response >(http_request, std::shared_ptr< http::http_pipeline_stage >)> &  handler)
inline

Adds an HTTP pipeline stage to the client.

Parameters
handlerA function object representing the pipeline stage.
void web::http::client::http_client::add_handler ( const std::shared_ptr< http::http_pipeline_stage > &  stage)
inline

Adds an HTTP pipeline stage to the client.

Parameters
stageA shared pointer to a pipeline stage.
const uri & web::http::client::http_client::base_uri ( ) const

Gets the base URI.

Returns
A base URI initialized in constructor
const http_client_config & web::http::client::http_client::client_config ( ) const

Get client configuration object

Returns
A reference to the client configuration object.
_ASYNCRTIMP pplx::task<http_response> web::http::client::http_client::request ( http_request  request,
const pplx::cancellation_token token = pplx::cancellation_token::none() 
)

Asynchronously sends an HTTP request.

Parameters
requestRequest to send.
tokenCancellation token for cancellation of this request operation.
Returns
An asynchronous operation that is completed once a response from the request is received.
pplx::task<http_response> web::http::client::http_client::request ( const method mtd,
const pplx::cancellation_token token = pplx::cancellation_token::none() 
)
inline

Asynchronously sends an HTTP request.

Parameters
mtdHTTP request method.
tokenCancellation token for cancellation of this request operation.
Returns
An asynchronous operation that is completed once a response from the request is received.
pplx::task<http_response> web::http::client::http_client::request ( const method mtd,
const utility::string_t &  path_query_fragment,
const pplx::cancellation_token token = pplx::cancellation_token::none() 
)
inline

Asynchronously sends an HTTP request.

Parameters
mtdHTTP request method.
path_query_fragmentString containing the path, query, and fragment, relative to the http_client's base URI.
tokenCancellation token for cancellation of this request operation.
Returns
An asynchronous operation that is completed once a response from the request is received.
pplx::task<http_response> web::http::client::http_client::request ( const method mtd,
const utility::string_t &  path_query_fragment,
const json::value body_data,
const pplx::cancellation_token token = pplx::cancellation_token::none() 
)
inline

Asynchronously sends an HTTP request.

Parameters
mtdHTTP request method.
path_query_fragmentString containing the path, query, and fragment, relative to the http_client's base URI.
body_dataThe data to be used as the message body, represented using the json object library.
tokenCancellation token for cancellation of this request operation.
Returns
An asynchronous operation that is completed once a response from the request is received.
pplx::task<http_response> web::http::client::http_client::request ( const method mtd,
const utf8string &  path_query_fragment,
const utf8string &  body_data,
const utf8string &  content_type = "text/plain; charset=utf-8",
const pplx::cancellation_token token = pplx::cancellation_token::none() 
)
inline

Asynchronously sends an HTTP request with a string body. Assumes the character encoding of the string is UTF-8.

Parameters
mtdHTTP request method.
path_query_fragmentString containing the path, query, and fragment, relative to the http_client's base URI.
content_typeA string holding the MIME type of the message body.
body_dataString containing the text to use in the message body.
tokenCancellation token for cancellation of this request operation.
Returns
An asynchronous operation that is completed once a response from the request is received.
pplx::task<http_response> web::http::client::http_client::request ( const method mtd,
const utf8string &  path_query_fragment,
utf8string &&  body_data,
const utf8string &  content_type = "text/plain; charset=utf-8",
const pplx::cancellation_token token = pplx::cancellation_token::none() 
)
inline

Asynchronously sends an HTTP request with a string body. Assumes the character encoding of the string is UTF-8.

Parameters
mtdHTTP request method.
path_query_fragmentString containing the path, query, and fragment, relative to the http_client's base URI.
content_typeA string holding the MIME type of the message body.
body_dataString containing the text to use in the message body.
tokenCancellation token for cancellation of this request operation.
Returns
An asynchronous operation that is completed once a response from the request is received.
pplx::task<http_response> web::http::client::http_client::request ( const method mtd,
const utf16string &  path_query_fragment,
const utf16string &  body_data,
const utf16string &  content_type = ::utility::conversions::to_utf16string("text/plain"),
const pplx::cancellation_token token = pplx::cancellation_token::none() 
)
inline

Asynchronously sends an HTTP request with a string body. Assumes the character encoding of the string is UTF-16 will perform conversion to UTF-8.

Parameters
mtdHTTP request method.
path_query_fragmentString containing the path, query, and fragment, relative to the http_client's base URI.
content_typeA string holding the MIME type of the message body.
body_dataString containing the text to use in the message body.
tokenCancellation token for cancellation of this request operation.
Returns
An asynchronous operation that is completed once a response from the request is received.
pplx::task<http_response> web::http::client::http_client::request ( const method mtd,
const utf8string &  path_query_fragment,
const utf8string &  body_data,
const pplx::cancellation_token token 
)
inline

Asynchronously sends an HTTP request with a string body. Assumes the character encoding of the string is UTF-8.

Parameters
mtdHTTP request method.
path_query_fragmentString containing the path, query, and fragment, relative to the http_client's base URI.
body_dataString containing the text to use in the message body.
tokenCancellation token for cancellation of this request operation.
Returns
An asynchronous operation that is completed once a response from the request is received.
pplx::task<http_response> web::http::client::http_client::request ( const method mtd,
const utf8string &  path_query_fragment,
utf8string &&  body_data,
const pplx::cancellation_token token 
)
inline

Asynchronously sends an HTTP request with a string body. Assumes the character encoding of the string is UTF-8.

Parameters
mtdHTTP request method.
path_query_fragmentString containing the path, query, and fragment, relative to the http_client's base URI.
body_dataString containing the text to use in the message body.
tokenCancellation token for cancellation of this request operation.
Returns
An asynchronous operation that is completed once a response from the request is received.
pplx::task<http_response> web::http::client::http_client::request ( const method mtd,
const utf16string &  path_query_fragment,
const utf16string &  body_data,
const pplx::cancellation_token token 
)
inline

Asynchronously sends an HTTP request with a string body. Assumes the character encoding of the string is UTF-16 will perform conversion to UTF-8.

Parameters
mtdHTTP request method.
path_query_fragmentString containing the path, query, and fragment, relative to the http_client's base URI.
body_dataString containing the text to use in the message body.
tokenCancellation token for cancellation of this request operation.
Returns
An asynchronous operation that is completed once a response from the request is received.
pplx::task<http_response> web::http::client::http_client::request ( const method mtd,
const utility::string_t &  path_query_fragment,
const concurrency::streams::istream &  body,
const utility::string_t &  content_type = _XPLATSTR("application/octet-stream"),
const pplx::cancellation_token token = pplx::cancellation_token::none() 
)
inline

Asynchronously sends an HTTP request.

Parameters
mtdHTTP request method.
path_query_fragmentString containing the path, query, and fragment, relative to the http_client's base URI.
bodyAn asynchronous stream representing the body data.
content_typeA string holding the MIME type of the message body.
tokenCancellation token for cancellation of this request operation.
Returns
A task that is completed once a response from the request is received.
pplx::task<http_response> web::http::client::http_client::request ( const method mtd,
const utility::string_t &  path_query_fragment,
const concurrency::streams::istream &  body,
const pplx::cancellation_token token 
)
inline

Asynchronously sends an HTTP request.

Parameters
mtdHTTP request method.
path_query_fragmentString containing the path, query, and fragment, relative to the http_client's base URI.
bodyAn asynchronous stream representing the body data.
tokenCancellation token for cancellation of this request operation.
Returns
A task that is completed once a response from the request is received.
pplx::task<http_response> web::http::client::http_client::request ( const method mtd,
const utility::string_t &  path_query_fragment,
const concurrency::streams::istream &  body,
size_t  content_length,
const utility::string_t &  content_type = _XPLATSTR("application/octet-stream"),
const pplx::cancellation_token token = pplx::cancellation_token::none() 
)
inline

Asynchronously sends an HTTP request.

Parameters
mtdHTTP request method.
path_query_fragmentString containing the path, query, and fragment, relative to the http_client's base URI.
bodyAn asynchronous stream representing the body data.
content_lengthSize of the message body.
content_typeA string holding the MIME type of the message body.
tokenCancellation token for cancellation of this request operation.
Returns
A task that is completed once a response from the request is received.

Winrt requires to provide content_length.

pplx::task<http_response> web::http::client::http_client::request ( const method mtd,
const utility::string_t &  path_query_fragment,
const concurrency::streams::istream &  body,
size_t  content_length,
const pplx::cancellation_token token 
)
inline

Asynchronously sends an HTTP request.

Parameters
mtdHTTP request method.
path_query_fragmentString containing the path, query, and fragment, relative to the http_client's base URI.
bodyAn asynchronous stream representing the body data.
content_lengthSize of the message body.
tokenCancellation token for cancellation of this request operation.
Returns
A task that is completed once a response from the request is received.

Winrt requires to provide content_length.


The documentation for this class was generated from the following files: