aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/monitoring/httpapiservice.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2025-12-11 09:34:24 +0100
committerGitHub Enterprise <[email protected]>2025-12-11 09:34:24 +0100
commit3de9a65cd990f2a4f5395b7e2a094471633eb98b (patch)
treef1640a32fd2b68a8f1b6f77f5ba5c4cbf959cb0b /src/zenhttp/monitoring/httpapiservice.cpp
parent5.7.14-pre3 (diff)
downloadzen-3de9a65cd990f2a4f5395b7e2a094471633eb98b.tar.xz
zen-3de9a65cd990f2a4f5395b7e2a094471633eb98b.zip
HTTP server API changes for improved extensibility (#684)
* refactored `HttpServer` so all subclass member functions are proctected, to make it easier to extend base functionality * added API service, can be used to enumerate registered endpoints (at `/api`). Currently only very basic information is provided
Diffstat (limited to 'src/zenhttp/monitoring/httpapiservice.cpp')
-rw-r--r--src/zenhttp/monitoring/httpapiservice.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/zenhttp/monitoring/httpapiservice.cpp b/src/zenhttp/monitoring/httpapiservice.cpp
new file mode 100644
index 000000000..f8cfa25f4
--- /dev/null
+++ b/src/zenhttp/monitoring/httpapiservice.cpp
@@ -0,0 +1,47 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#include <zenhttp/httpapiservice.h>
+
+#include <zencore/compactbinarybuilder.h>
+
+namespace zen {
+
+HttpApiService::HttpApiService(HttpServer& Server) : m_Server(Server)
+{
+ m_Router.RegisterRoute(
+ "",
+ [&](HttpRouterRequest& Request) {
+ CbObjectWriter ResponseData;
+
+ ResponseData.BeginArray("services");
+
+ m_Server.EnumerateServices([&](HttpService& Service) {
+ ResponseData.BeginObject();
+ ResponseData << "base_uri" << Service.BaseUri();
+ ResponseData.EndObject();
+ });
+
+ ResponseData.EndArray();
+
+ Request.ServerRequest().WriteResponse(HttpResponseCode::OK, ResponseData.Save());
+ },
+ HttpVerb::kGet);
+}
+
+HttpApiService::~HttpApiService()
+{
+}
+
+const char*
+HttpApiService::BaseUri() const
+{
+ return "/api/";
+}
+
+void
+HttpApiService::HandleRequest(HttpServerRequest& HttpServiceRequest)
+{
+ m_Router.HandleRequest(HttpServiceRequest);
+}
+
+} // namespace zen