Polyphase Game Engine
Loading...
Searching...
No Matches
HttpClient.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <stdint.h>
5#include <string>
6#include <vector>
7
8#include "PolyphaseAPI.h"
12
13using HttpResponseCallback = std::function<void(const HttpResponse&)>;
14
15namespace Http
16{
17 // Lifecycle. Initialize is called from Engine::Initialize after NET_Initialize.
20
21 // Pumps the main-thread completion queue. Called once per frame from
22 // Engine::Update so callbacks fire on the main thread (Lua-safe).
23 POLYPHASE_API void Tick();
24
25 // Returns false on platforms with no working backend (Android, or Linux
26 // without libcurl present at runtime).
28
29 // Diagnostic message for environments where IsAvailable() returns false
30 // (e.g. "Install libcurl4 to enable HTTP support."). Empty string when
31 // available.
33
34 // Async send. Callback is invoked on the main thread once the response is
35 // complete (or on error). Returns a handle that can be used to Cancel().
37
38 POLYPHASE_API HttpHandle Get (const std::string& url, HttpResponseCallback cb);
39 POLYPHASE_API HttpHandle Post (const std::string& url, std::vector<uint8_t> body, HttpResponseCallback cb);
40 POLYPHASE_API HttpHandle Put (const std::string& url, std::vector<uint8_t> body, HttpResponseCallback cb);
41 POLYPHASE_API HttpHandle Patch (const std::string& url, std::vector<uint8_t> body, HttpResponseCallback cb);
42 POLYPHASE_API HttpHandle Delete(const std::string& url, HttpResponseCallback cb);
43
44 // Convenience POST with a string body (utf-8, content-type unchanged).
45 POLYPHASE_API HttpHandle PostString(const std::string& url, const std::string& body, HttpResponseCallback cb);
46
47 // Synchronous send. Blocks the calling thread until the response is
48 // available. Intended for tests/tools — DO NOT call from gameplay code or
49 // the main thread.
51}
std::function< void(const HttpResponse &)> HttpResponseCallback
Definition HttpClient.h:13
Export macros for Polyphase Engine symbols.
#define POLYPHASE_API
Definition PolyphaseAPI.h:31
Definition HttpHandle.h:10
Definition HttpRequest.h:20
Definition HttpResponse.h:16
Definition HttpClient.cpp:123
bool IsAvailable()
Definition HttpClient.cpp:224
void Initialize()
Definition HttpClient.cpp:124
void Shutdown()
Definition HttpClient.cpp:148
HttpHandle PostString(const std::string &url, const std::string &body, HttpResponseCallback cb)
Definition HttpClient.cpp:294
HttpResponse SendSync(HttpRequest req)
Definition HttpClient.cpp:299
void Tick()
Definition HttpClient.cpp:202
const char * GetMissingDependencyMessage()
Definition HttpClient.cpp:231
HttpHandle Send(HttpRequest req, HttpResponseCallback cb)
Definition HttpClient.cpp:237