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.
WebCC/webcc/rest_async_client.h

61 lines
1.6 KiB
C++

#ifndef WEBCC_REST_ASYNC_CLIENT_H_
#define WEBCC_REST_ASYNC_CLIENT_H_
#include <string>
#include <utility> // for move()
#include "webcc/http_async_client.h"
namespace webcc {
class RestAsyncClient {
public:
RestAsyncClient(boost::asio::io_context& io_context, // NOLINT
const std::string& host, const std::string& port);
void set_timeout_seconds(int timeout_seconds) {
timeout_seconds_ = timeout_seconds;
}
void Get(const std::string& url,
HttpResponseHandler response_handler) {
Request(kHttpGet, url, "", response_handler);
}
void Post(const std::string& url, std::string&& content,
HttpResponseHandler response_handler) {
Request(kHttpPost, url, std::move(content), response_handler);
}
void Put(const std::string& url, std::string&& content,
HttpResponseHandler response_handler) {
Request(kHttpPut, url, std::move(content), response_handler);
}
void Patch(const std::string& url, std::string&& content,
HttpResponseHandler response_handler) {
Request(kHttpPatch, url, std::move(content), response_handler);
}
void Delete(const std::string& url,
HttpResponseHandler response_handler) {
Request(kHttpDelete, url, "", response_handler);
}
private:
void Request(const std::string& method, const std::string& url,
std::string&& content, HttpResponseHandler response_handler);
boost::asio::io_context& io_context_;
std::string host_;
std::string port_;
// Timeout in seconds; only effective when > 0.
int timeout_seconds_;
};
} // namespace webcc
#endif // WEBCC_REST_ASYNC_CLIENT_H_