aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.cpp
blob: 57e4686ca05bfe1a3600789d6d8af230a9f38cab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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;
}

// curl -d '{"a":"5", "b":"12"}' -H "Content-Type: application/json" -X POST http://localhost:18080/add_json