-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.h
More file actions
56 lines (37 loc) · 1.93 KB
/
Copy pathapi.h
File metadata and controls
56 lines (37 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef API_H
#define API_H
#include <string>
#include <thread>
#include <map>
#include "Simple-Web-Server/server_http.hpp"
#include <nlohmann/json.hpp>
using HttpServer = SimpleWeb::Server<SimpleWeb::HTTP>;
namespace API {
inline HttpServer server;
inline std::thread serverThread;
inline void writeJSON(std::shared_ptr<HttpServer::Response> response, const nlohmann::json json, const std::string status_code = "200 OK");
inline std::map<std::string, std::string> parseQueryString(const std::shared_ptr<HttpServer::Request> request);
inline bool parseBody(const std::shared_ptr<HttpServer::Request> request, nlohmann::json& body);
inline void defineRoutes();
void startAPI(const int apiPort, const std::string apiAddress);
}
namespace Endpoints {
namespace GET {
void index(std::shared_ptr<HttpServer::Response> response, std::shared_ptr<HttpServer::Request> request);
void cursor(std::shared_ptr<HttpServer::Response> response, std::shared_ptr<HttpServer::Request> request);
void collection(std::shared_ptr<HttpServer::Response> response, std::shared_ptr<HttpServer::Request> request);
}
namespace POST {
void indexes(std::shared_ptr<HttpServer::Response> response, std::shared_ptr<HttpServer::Request> request);
void bulk(std::shared_ptr<HttpServer::Response> response, std::shared_ptr<HttpServer::Request> request);
std::function<void(std::shared_ptr<HttpServer::Response>, std::shared_ptr<HttpServer::Request>)> crud_wrapper(std::function<void(nlohmann::json&, nlohmann::json&)> func, const std::string operation);
}
void POST_Index(nlohmann::json&, nlohmann::json&);
void GET_cursor(nlohmann::json&, nlohmann::json&);
void GET_collection(nlohmann::json&, nlohmann::json&);
std::function<void(std::shared_ptr<HttpServer::Response>, std::shared_ptr<HttpServer::Request>)> Preprocessing(
std::function<void(std::shared_ptr<HttpServer::Response>, std::shared_ptr<HttpServer::Request>)> func,
bool inThread = true
);
}
#endif