10Duke Scale C++ Client
All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
HTTPRequestBuilder.h
1#ifndef TENDUKE_HTTP_HTTPREQUESTBUILDER_H
2#define TENDUKE_HTTP_HTTPREQUESTBUILDER_H
3
4#include "./HTTPRequest.h"
5#include "./HTTPRequestAuthenticator.h"
6#include "net/URLBuilder.h"
7#include "net/URLEncoder.h"
8
9#include <string>
10#include <memory>
11#include <map>
12
13namespace tenduke { namespace http {
14
15class HTTPCall;
16class HTTPClient;
17
22{
23public:
31 explicit HTTPRequestBuilder(
32 std::shared_ptr<const tenduke::net::URLEncoder> urlEncoder,
33 tenduke::http::HTTPClient * client = nullptr,
34 long connectionTimeoutMs = tenduke::http::DEFAULT_CONNECTION_TIMEOUT_MS,
36 );
37
42 std::unique_ptr<HTTPRequest> build();
43
52 std::unique_ptr<HTTPCall> call();
53
59
65
71 HTTPRequestBuilder & url(const std::string &url);
72
78 HTTPRequestBuilder & authenticateWith(const std::shared_ptr<const tenduke::http::HTTPRequestAuthenticator> &requestAuthenticator);
79
87 HTTPRequestBuilder & header(const std::string &name, const std::string &value, bool skipIfValueEmpty = true);
88
95 HTTPRequestBuilder & formParameter(const std::string &name, const std::string &value);
96
102 HTTPRequestBuilder & contentType(const std::string &contentType);
103
109 HTTPRequestBuilder & charset(const std::string &charset);
110
117
123 HTTPRequestBuilder & body(const std::string &requestEntity);
124
130
131
132protected:
137
138private:
139 const tenduke::http::HTTPClient * client;
140 const std::shared_ptr<const tenduke::net::URLEncoder> urlEncoder;
141
142 std::string method;
143 std::string requestEntity; // aka body
144 std::string URL;
145 std::shared_ptr<const tenduke::http::HTTPRequestAuthenticator> requestAuthenticator;
146 std::multimap<std::string, std::string> headers;
147 std::multimap<std::string, std::string> formParameters;
148 std::string requestContentType;
149 std::string requestCharset;
150
151 long connectionTimeoutMs;
152 long timeoutMs;
153};
154
155
156}}
157
158#endif // TENDUKE_HTTP_HTTPREQUESTBUILDER_H
A simple HTTP-client.
Definition HTTPClient.h:19
Builds HTTPRequest.
Definition HTTPRequestBuilder.h:22
HTTPRequestBuilder & get()
Sets the method to GET.
Definition HTTPRequestBuilder.cpp:79
HTTPRequestBuilder & body(const std::string &requestEntity)
Sets body as string.
Definition HTTPRequestBuilder.cpp:103
tenduke::net::URLBuilder url()
Starts URL-building.
Definition HTTPRequestBuilder.cpp:147
HTTPRequestBuilder & contentType(const std::string &contentType)
Sets content-type.
Definition HTTPRequestBuilder.cpp:130
HTTPRequestBuilder & formParameter(const std::string &name, const std::string &value)
Adds form-parameter to the request.
Definition HTTPRequestBuilder.cpp:110
HTTPRequestBuilder & post()
Sets the method to POST.
Definition HTTPRequestBuilder.cpp:85
std::unique_ptr< HTTPRequest > build()
Builds the request.
Definition HTTPRequestBuilder.cpp:21
HTTPRequestBuilder & header(const std::string &name, const std::string &value, bool skipIfValueEmpty=true)
Adds header to the request.
Definition HTTPRequestBuilder.cpp:118
HTTPRequestBuilder & charset(const std::string &charset)
Sets character set.
Definition HTTPRequestBuilder.cpp:136
std::unique_ptr< HTTPCall > call()
Builds the request, and builds the call in one call.
Definition HTTPRequestBuilder.cpp:51
std::string buildMessageBodyFromFormParameters()
Builds the message body from form-parameters.
Definition HTTPRequestBuilder.cpp:60
HTTPRequestBuilder & authenticateWith(const std::shared_ptr< const tenduke::http::HTTPRequestAuthenticator > &requestAuthenticator)
Sets the request authenticator.
Definition HTTPRequestBuilder.cpp:97
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.
Definition HTTPRequestBuilder.cpp:10
HTTPRequestBuilder & utf8()
Sets the character set to UTF-8.
Definition HTTPRequestBuilder.cpp:142
Very simple URL-builder.
Definition URLBuilder.h:19
const long DEFAULT_CONNECTION_TIMEOUT_MS
Default connection time out in milliseconds.
Definition HTTPRequest.h:13
const long DEFAULT_TIMEOUT_MS
Default total time out in milliseconds.
Definition HTTPRequest.h:16
Root for classes, functions and globals of 10Duke C++ Client.
Definition BackendConfiguration.h:7