diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
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 <iostream> +#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 |