10Duke Scale C++ Client
Loading...
Searching...
No Matches
tenduke::http::HTTPRequestBuilder Class Reference

#include <HTTPRequestBuilder.h>

Detailed Description

Builds HTTPRequest.

Public Member Functions

 HTTPRequestBuilder (std::shared_ptr< const tenduke::net::URLEncoder > urlEncoder, tenduke::http::HTTPClient *client=nullptr, long connectionTimeoutMs=tenduke::http::DEFAULT_CONNECTION_TIMEOUT_MS, long timeoutMs=tenduke::http::DEFAULT_TIMEOUT_MS)
 Constructs new instance.
 
std::unique_ptr< HTTPRequestbuild ()
 Builds the request.
 
std::unique_ptr< HTTPCallcall ()
 Builds the request, and builds the call in one call.
 
HTTPRequestBuilderget ()
 Sets the method to GET.
 
HTTPRequestBuilderpost ()
 Sets the method to POST.
 
HTTPRequestBuilderurl (const std::string &url)
 Sets the request URL.
 
HTTPRequestBuilderauthenticateWith (const std::shared_ptr< const tenduke::http::HTTPRequestAuthenticator > &requestAuthenticator)
 Sets the request authenticator.
 
HTTPRequestBuilderheader (const std::string &name, const std::string &value, bool skipIfValueEmpty=true)
 Adds header to the request.
 
HTTPRequestBuilderformParameter (const std::string &name, const std::string &value)
 Adds form-parameter to the request.
 
HTTPRequestBuildercontentType (const std::string &contentType)
 Sets content-type.
 
HTTPRequestBuildercharset (const std::string &charset)
 Sets character set.
 
HTTPRequestBuilderutf8 ()
 Sets the character set to UTF-8.
 
HTTPRequestBuilderbody (const std::string &requestEntity)
 Sets body as string.
 
tenduke::net::URLBuilder url ()
 Starts URL-building.
 

Protected Member Functions

std::string buildMessageBodyFromFormParameters ()
 Builds the message body from form-parameters.
 

Constructor & Destructor Documentation

◆ HTTPRequestBuilder()

tenduke::http::HTTPRequestBuilder::HTTPRequestBuilder ( std::shared_ptr< const tenduke::net::URLEncoder urlEncoder,
tenduke::http::HTTPClient client = nullptr,
long  connectionTimeoutMs = tenduke::http::DEFAULT_CONNECTION_TIMEOUT_MS,
long  timeoutMs = tenduke::http::DEFAULT_TIMEOUT_MS 
)
explicit

Constructs new instance.

Parameters
urlEncoder-
client-
connectionTimeoutMs-
timeoutMs-

Member Function Documentation

◆ authenticateWith()

xdhttp::HTTPRequestBuilder & tenduke::http::HTTPRequestBuilder::authenticateWith ( const std::shared_ptr< const tenduke::http::HTTPRequestAuthenticator > &  requestAuthenticator)

Sets the request authenticator.

Parameters
requestAuthenticator-
Returns
instance for fluent method chaining.

◆ body()

xdhttp::HTTPRequestBuilder & tenduke::http::HTTPRequestBuilder::body ( const std::string &  requestEntity)

Sets body as string.

Parameters
requestEntity-
Returns
instance for fluent method chaining.

◆ build()

std::unique_ptr< xdhttp::HTTPRequest > tenduke::http::HTTPRequestBuilder::build ( )

Builds the request.

Returns
the request.

◆ buildMessageBodyFromFormParameters()

std::string tenduke::http::HTTPRequestBuilder::buildMessageBodyFromFormParameters ( )
protected

Builds the message body from form-parameters.

Returns
-

◆ call()

std::unique_ptr< xdhttp::HTTPCall > tenduke::http::HTTPRequestBuilder::call ( )

Builds the request, and builds the call in one call.

NOTE: if HTTP-client not present, you will get an exception.

Remember to execute the call.

Returns
call for the request
Exceptions
tenduke::http::HTTPExceptionif the builder has not been configured with HTTP-client

◆ charset()

xdhttp::HTTPRequestBuilder & tenduke::http::HTTPRequestBuilder::charset ( const std::string &  charset)

Sets character set.

Parameters
charset-
Returns
instance for fluent method chaining.

◆ contentType()

xdhttp::HTTPRequestBuilder & tenduke::http::HTTPRequestBuilder::contentType ( const std::string &  contentType)

Sets content-type.

Parameters
contentType-
Returns
instance for fluent method chaining.

◆ formParameter()

xdhttp::HTTPRequestBuilder & tenduke::http::HTTPRequestBuilder::formParameter ( const std::string &  name,
const std::string &  value 
)

Adds form-parameter to the request.

The method will PCT-encode the parameter (name and value).

Parameters
name-
value-
Returns
instance for fluent method chaining.

◆ get()

xdhttp::HTTPRequestBuilder & tenduke::http::HTTPRequestBuilder::get ( )

Sets the method to GET.

Returns
this instance for fluent method chaining.

◆ header()

xdhttp::HTTPRequestBuilder & tenduke::http::HTTPRequestBuilder::header ( const std::string &  name,
const std::string &  value,
bool  skipIfValueEmpty = true 
)

Adds header to the request.

Parameters
namename of the header
valuevalue of the header
skipIfValueEmptyif true and value is empty, the header will not be added.
Returns
instance for fluent method chaining.

◆ post()

xdhttp::HTTPRequestBuilder & tenduke::http::HTTPRequestBuilder::post ( )

Sets the method to POST.

Returns
instance for fluent method chaining.

◆ url() [1/2]

xdnet::URLBuilder tenduke::http::HTTPRequestBuilder::url ( )

Starts URL-building.

Returns
-

◆ url() [2/2]

xdhttp::HTTPRequestBuilder & tenduke::http::HTTPRequestBuilder::url ( const std::string &  url)

Sets the request URL.

Parameters
url-
Returns
instance for fluent method chaining.

◆ utf8()

xdhttp::HTTPRequestBuilder & tenduke::http::HTTPRequestBuilder::utf8 ( )

Sets the character set to UTF-8.

(Syntactic sugar).

Returns
instance for fluent method chaining.

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