From 428b1f61474c2da66ba4f5ecfca0188f866817b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Sverre=20Lien=20Sell=C3=A6g?= Date: Sat, 22 May 2021 19:32:10 +0200 Subject: [PATCH] connect process to a put command --- src/store.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/store.cpp b/src/store.cpp index f4b4130..93772af 100644 --- a/src/store.cpp +++ b/src/store.cpp @@ -52,6 +52,37 @@ int Application::run() { {header_access_control, header_application_data}); }; + http_server.resource["^/orders/?$"]["PUT"] = + [&](std::shared_ptr response, + std::shared_ptr request) { + const auto content_type = request->header.find("Content-Type"); + + const auto missing_content_type = content_type == request->header.end(); + if (missing_content_type) { + return response::not_found(response); + } + + const auto is_json = content_type->second == "application/json"; + if (!is_json) { + return response::not_found(response); + } + + json data = nullptr; + try { + request->content >> data; + } catch (...) { + return response::not_found(response); + } + + if (!data.is_object()) { + return response::not_found(response); + } + + const auto j = dat.process(data); + + response->write(Status::success_ok, data.dump(), + {header_access_control, header_application_data}); + }; servers.emplace_back([&]() { http_server.start(web_server_started); });