Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Requests.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <vector>
5#include <mutex>
6#include "API/Base.h"
7
8namespace API
9{
11 {
12 public:
13 ARK_API static Requests& Get();
14
15 Requests();
16 ~Requests();
17
18 Requests(const Requests&) = delete;
19 Requests(Requests&&) = delete;
20 Requests& operator=(const Requests&) = delete;
21 Requests& operator=(Requests&&) = delete;
22
23 /**
24 * \brief Creates an async GET Request that runs in another thread but calls the callback from the main thread
25 * \param request URL
26 * \param the callback function, binds sucess(bool) and result(string), result is error code if request failed and the response otherwise
27 * \param included headers
28 */
29 ARK_API bool CreateGetRequest(const std::string& url,
30 const std::function<void(bool, std::string)>& callback,
31 std::vector<std::string> headers = {});
32
33 /**
34 * \brief Creates an async POST Request with application/x-www-form-urlencoded content type that runs in another thread but calls the callback from the main thread
35 * \param request URL
36 * \param the callback function, binds sucess(bool) and result(string), result is error code if request failed and the response otherwise
37 * \param data to post
38 * \param included headers
39 */
40 ARK_API bool CreatePostRequest(const std::string& url,
41 const std::function<void(bool, std::string)>& callback,
42 const std::string& post_data,
43 std::vector<std::string> headers = {});
44
45 /**
46 * \brief Creates an async POST Request that runs in another thread but calls the callback from the main thread
47 * \param request URL
48 * \param the callback function, binds sucess(bool) and result(string), result is error code if request failed and the response otherwise
49 * \param data to post
50 * \param content type
51 * \param included headers
52 */
53 ARK_API bool CreatePostRequest(const std::string& url,
54 const std::function<void(bool, std::string)>& callback,
55 const std::string& post_data,
56 const std::string& content_type,
57 std::vector<std::string> headers = {});
58
59 /**
60 * \brief Creates an async POST Request that runs in another thread but calls the callback from the main thread
61 * \param request URL
62 * \param the callback function, binds sucess(bool) and result(string), result is error code if request failed and the response otherwise
63 * \param data key
64 * \param data value
65 * \param included headers
66 */
67 ARK_API bool CreatePostRequest(const std::string& url,
68 const std::function<void(bool, std::string)>& callback,
69 const std::vector<std::string>& post_ids,
70 const std::vector<std::string>& post_data,
71 std::vector<std::string> headers = {});
72
73 /**
74 * \brief Creates an async DELETE Request that runs in another thread but calls the callback from the main thread
75 * \param request URL
76 * \param the callback function, binds sucess(bool) and result(string), result is error code if request failed and the response otherwise
77 * \param included headers
78 */
79 ARK_API bool CreateDeleteRequest(const std::string& url,
80 const std::function<void(bool, std::string)>& callback,
81 std::vector<std::string> headers = {});
82 private:
83 class impl;
84 std::unique_ptr<impl> pimpl;
85 };
86} // namespace API
#define ARK_API
Definition Base.h:9
virtual std::unique_ptr< ArkApi::ICommands > & GetCommands()=0
std::mutex RequestMutex_
Definition Requests.cpp:47
void WriteRequest(std::function< void(bool, std::string)> callback, bool success, std::string result)
Definition Requests.cpp:73
std::string GetResponse(Poco::Net::HTTPClientSession *session, Poco::Net::HTTPResponse &response)
Definition Requests.cpp:107
Poco::Net::HTTPRequest ConstructRequest(const std::string &url, Poco::Net::HTTPClientSession *&session, const std::vector< std::string > &headers, const std::string &request_type)
Definition Requests.cpp:79
std::vector< RequestData > RequestsVec_
Definition Requests.cpp:46
Requests(Requests &&)=delete
ARK_API bool CreateGetRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, std::vector< std::string > headers={})
Creates an async GET Request that runs in another thread but calls the callback from the main thread.
Definition Requests.cpp:129
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::vector< std::string > &post_ids, const std::vector< std::string > &post_data, std::vector< std::string > headers={})
Creates an async POST Request that runs in another thread but calls the callback from the main thread...
Definition Requests.cpp:238
Requests & operator=(Requests &&)=delete
ARK_API bool CreateDeleteRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, std::vector< std::string > headers={})
Creates an async DELETE Request that runs in another thread but calls the callback from the main thre...
Definition Requests.cpp:292
Requests & operator=(const Requests &)=delete
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::string &post_data, std::vector< std::string > headers={})
Creates an async POST Request with application/x-www-form-urlencoded content type that runs in anothe...
Definition Requests.cpp:162
static ARK_API Requests & Get()
Definition Requests.cpp:67
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::string &post_data, const std::string &content_type, std::vector< std::string > headers={})
Creates an async POST Request that runs in another thread but calls the callback from the main thread...
Definition Requests.cpp:200
std::unique_ptr< impl > pimpl
Definition Requests.h:84
Requests(const Requests &)=delete
virtual void AddOnTickCallback(const FString &id, const std::function< void(float)> &callback)=0
Added function will be called every frame.
virtual bool RemoveOnTickCallback(const FString &id)=0
Removes a on-tick callback.
Definition Logger.h:9
static std::shared_ptr< spdlog::logger > & GetLog()
Definition Logger.h:22
std::string displayText() const
Returns the exception code if defined.
virtual std::istream & receiveResponse(HTTPResponse &response)
virtual std::ostream & sendRequest(HTTPRequest &request)
Returns the connection timeout for HTTP connections.
static const std::string HTTP_1_1
void setContentLength(std::streamsize length)
Returns the HTTP version for this message.
HTTPRequest(const std::string &method, const std::string &uri, const std::string &version)
Creates a HTTP/1.0 request with the given method and URI.
static const std::string HTTP_GET
static const std::string HTTP_DELETE
static const std::string HTTP_POST
const std::string & getReason() const
Sets the HTTP reason phrase.
HTTPResponse(HTTPStatus status)
HTTPStatus getStatus() const
HTTPSClientSession(const std::string &host, Poco::UInt16 port=HTTPS_PORT)
RejectCertificateHandler(bool handleErrorsOnServerSide)
void initializeClient(PrivateKeyPassphraseHandlerPtr ptrPassphraseHandler, InvalidCertificateHandlerPtr ptrHandler, Context::Ptr ptrContext)
static SSLManager & instance()
This stream discards all characters written to it.
Definition NullStream.h:77
static std::streamsize copyStream(std::istream &istr, std::ostream &ostr, std::size_t bufferSize=8192)
const std::string & getHost() const
Sets the user-info part of the URI.
Definition URI.h:385
const std::string & getScheme() const
Definition URI.h:373
URI(const std::string &uri)
Creates an empty URI.
unsigned short getPort() const
Sets the host part of the URI.
std::string getPathAndQuery() const
Returns the encoded path, query and fragment parts of the URI.
void error(const T &)
Definition IBaseApi.h:9
std::unique_ptr< IBaseApi > game_api
Definition IBaseApi.h:25
void NetSSL_API initializeSSL()
void NetSSL_API uninitializeSSL()
Definition format.h:408
Definition json.hpp:4518
std::function< void(bool, std::string)> callback
Definition Requests.cpp:41
static std::string escape(const std::string &s, bool strictJSON=false)