You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.7 KiB
C
63 lines
1.7 KiB
C
![]()
7 years ago
|
#ifndef WEBCC_REST_ASYNC_CLIENT_H_
|
||
|
#define WEBCC_REST_ASYNC_CLIENT_H_
|
||
![]()
7 years ago
|
|
||
|
#include <string>
|
||
![]()
7 years ago
|
#include <utility> // for move()
|
||
![]()
7 years ago
|
|
||
![]()
7 years ago
|
#include "webcc/http_async_client.h"
|
||
![]()
7 years ago
|
|
||
|
namespace webcc {
|
||
|
|
||
![]()
7 years ago
|
class RestAsyncClient {
|
||
![]()
7 years ago
|
public:
|
||
![]()
7 years ago
|
RestAsyncClient(boost::asio::io_context& io_context, // NOLINT
|
||
![]()
7 years ago
|
const std::string& host, const std::string& port);
|
||
![]()
7 years ago
|
|
||
|
void set_timeout_seconds(int timeout_seconds) {
|
||
|
timeout_seconds_ = timeout_seconds;
|
||
![]()
7 years ago
|
}
|
||
|
|
||
|
void Get(const std::string& url,
|
||
|
HttpResponseHandler response_handler) {
|
||
|
Request(kHttpGet, url, "", response_handler);
|
||
|
}
|
||
|
|
||
![]()
7 years ago
|
void Post(const std::string& url, std::string&& content,
|
||
![]()
7 years ago
|
HttpResponseHandler response_handler) {
|
||
![]()
7 years ago
|
Request(kHttpPost, url, std::move(content), response_handler);
|
||
![]()
7 years ago
|
}
|
||
|
|
||
![]()
7 years ago
|
void Put(const std::string& url, std::string&& content,
|
||
![]()
7 years ago
|
HttpResponseHandler response_handler) {
|
||
![]()
7 years ago
|
Request(kHttpPut, url, std::move(content), response_handler);
|
||
![]()
7 years ago
|
}
|
||
|
|
||
![]()
7 years ago
|
void Patch(const std::string& url, std::string&& content,
|
||
![]()
7 years ago
|
HttpResponseHandler response_handler) {
|
||
![]()
7 years ago
|
Request(kHttpPatch, url, std::move(content), response_handler);
|
||
![]()
7 years ago
|
}
|
||
|
|
||
|
void Delete(const std::string& url,
|
||
|
HttpResponseHandler response_handler) {
|
||
|
Request(kHttpDelete, url, "", response_handler);
|
||
|
}
|
||
|
|
||
|
private:
|
||
![]()
7 years ago
|
void Request(const std::string& method, const std::string& url,
|
||
|
std::string&& content, HttpResponseHandler response_handler);
|
||
![]()
7 years ago
|
|
||
|
boost::asio::io_context& io_context_;
|
||
![]()
7 years ago
|
|
||
![]()
7 years ago
|
std::string host_;
|
||
|
std::string port_;
|
||
![]()
7 years ago
|
|
||
![]()
7 years ago
|
HttpResponseHandler response_handler_;
|
||
![]()
7 years ago
|
|
||
|
// Timeout in seconds; only effective when > 0.
|
||
|
int timeout_seconds_;
|
||
![]()
7 years ago
|
};
|
||
|
|
||
|
} // namespace webcc
|
||
|
|
||
![]()
7 years ago
|
#endif // WEBCC_REST_ASYNC_CLIENT_H_
|