diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-12-14 22:07:03 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-02-02 21:25:06 +0100 |
| commit | 8533efde9d16a5d6e2b879c61cb579a97f501b40 (patch) | |
| tree | afd5e982ce7bad0f9b1d7d106164ff6087c5e359 | |
| parent | 5c1f0476063cce08d4362476863f80f74892d45c (diff) | |
WIP: add content support to the HTTP API.
| -rw-r--r-- | src/lib/http_server.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/http_server.cc b/src/lib/http_server.cc index 47e62d336..61264df14 100644 --- a/src/lib/http_server.cc +++ b/src/lib/http_server.cc @@ -157,6 +157,28 @@ HTTPServer::get(string const& url) } } return Response::ERROR_404; + } else if (url == "/api/v1/content") { + nlohmann::json json; + for (auto i: ContentStore::instance()->all()) { + json.push_back(SPLEntry(i).as_json()); + } + auto response = Response(200, json.dump()); + response.set_type(Response::Type::JSON); + return response; + } else if (boost::algorithm::starts_with(url, "/api/v1/content/")) { + vector<string> parts; + boost::algorithm::split(parts, url, boost::is_any_of("/")); + if (parts.size() != 5) { + return Response::ERROR_404; + } + auto content = ContentStore::instance()->get(parts[4]); + if (!content) { + return Response::ERROR_404; + } + auto json = SPLEntry(content).as_json(); + auto response = Response(200, json.dump()); + response.set_type(Response::Type::JSON); + return response; } else { LOG_HTTP("404 %1", url); return Response::ERROR_404; |
