Browse Source

connect process to a put command

master
Jørgen Sverre Lien Sellæg 5 years ago
parent
commit
428b1f6147
  1. 31
      src/store.cpp

31
src/store.cpp

@ -52,6 +52,37 @@ int Application::run() {
{header_access_control, header_application_data});
};
http_server.resource["^/orders/?$"]["PUT"] =
[&](std::shared_ptr<HttpServer::Response> response,
std::shared_ptr<HttpServer::Request> 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); });

Loading…
Cancel
Save