From 4fd77ac95998a9bff45e30a26f97e60159ad5e1d Mon Sep 17 00:00:00 2001 From: Niklas Halle Date: Sun, 23 Aug 2020 13:57:40 +0200 Subject: added crow and basic example --- src/main.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index d90e58d..57e4686 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,25 @@ #include +#include "crow.h" + int main() { + crow::SimpleApp app; + + CROW_ROUTE(app, "/add_json") + .methods("POST"_method) + ([](crow::request const &request) { + auto data = crow::json::load(request.body); + if (!data) + return crow::response(400); + auto sum = data["a"].i() + data["b"].i(); + std::ostringstream os; + os << sum; + return crow::response{os.str()}; + }); + + app.port(18080).multithreaded().run(); + std::cout << "Hello, World\n" << std::endl; -} \ No newline at end of file +} + +// curl -d '{"a":"5", "b":"12"}' -H "Content-Type: application/json" -X POST http://localhost:18080/add_json -- cgit v1.2.3-54-g00ecf