quick commit
This commit is contained in:
36
include/connection/httpConnection.hpp
Normal file
36
include/connection/httpConnection.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
struct HttpResponse {
|
||||
long status_code = 0;
|
||||
std::string body;
|
||||
std::map<std::string, std::string> headers;
|
||||
std::string error;
|
||||
|
||||
bool ok() const {
|
||||
return error.empty();
|
||||
}
|
||||
};
|
||||
|
||||
class HttpConnection {
|
||||
public:
|
||||
static HttpResponse get(const std::string &url,
|
||||
const std::map<std::string, std::string> &headers = {},
|
||||
long timeout_ms = 0);
|
||||
|
||||
static HttpResponse post(const std::string &url,
|
||||
const std::string &body,
|
||||
const std::map<std::string, std::string> &headers = {},
|
||||
const std::string &content_type = "application/json",
|
||||
long timeout_ms = 0);
|
||||
|
||||
private:
|
||||
static HttpResponse performRequest(const std::string &method,
|
||||
const std::string &url,
|
||||
const std::string &body,
|
||||
const std::map<std::string, std::string> &headers,
|
||||
const std::string &content_type,
|
||||
long timeout_ms);
|
||||
};
|
||||
Reference in New Issue
Block a user