Skip to content

Commit 3207f5f

Browse files
authored
Merge pull request #8 from StephanKa/feature/add-crow-cpp
added small example for using crow
2 parents fdb7a7f + 374ea63 commit 3207f5f

4 files changed

Lines changed: 59 additions & 1 deletion

File tree

cmake/Conan.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ macro(run_conan)
1818
sml/1.1.5
1919
nlohmann_json/3.10.5
2020
boost/1.78.0
21+
crowcpp-crow/1.0+1
2122
OPTIONS
2223
${CONAN_EXTRA_OPTIONS}
2324
gtest:build_gmock=True

src/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
OPTION(CPP_STARTER_USE_SML "Enable compilation of SML sample" OFF)
22
OPTION(CPP_STARTER_USE_BOOST_BEAST "Enable compilation of boost beast sample" OFF)
3+
OPTION(CPP_STARTER_USE_CROW "Enable compilation of crow sample" OFF)
34

45
# SML
56
IF(CPP_STARTER_USE_SML)
@@ -13,6 +14,12 @@ IF(CPP_STARTER_USE_BOOST_BEAST)
1314
ADD_SUBDIRECTORY(boost.beast)
1415
ENDIF()
1516

17+
# Crow
18+
IF(CPP_STARTER_USE_CROW)
19+
MESSAGE("Using Crow")
20+
ADD_SUBDIRECTORY(crow)
21+
ENDIF()
22+
1623

1724
# Generic test that uses conan libs
1825
ADD_EXECUTABLE(intro main.cpp)
@@ -23,4 +30,3 @@ TARGET_LINK_LIBRARIES(
2330
CONAN_PKG::docopt.cpp
2431
CONAN_PKG::fmt
2532
CONAN_PKG::spdlog)
26-

src/crow/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ADD_EXECUTABLE(test_crow main.cpp)
2+
TARGET_LINK_LIBRARIES(test_crow PRIVATE CONAN_PKG::crowcpp-crow CONAN_PKG::spdlog)

src/crow/main.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* example usage of crow-cpp http://crowcpp.org/ */
2+
#include "crow.h"
3+
4+
class a : public crow::returnable
5+
{
6+
public:
7+
a() : returnable("text/plain"){};
8+
9+
std::string dump() const override
10+
{
11+
return "ABCDF";
12+
}
13+
};
14+
15+
int main()
16+
{
17+
constexpr uint16_t port = 8080;
18+
std::vector<int> values;
19+
crow::SimpleApp app;
20+
21+
CROW_ROUTE(app, "/")
22+
([]() {
23+
return "Hello world";
24+
});
25+
26+
CROW_ROUTE(app, "/json")
27+
([] {
28+
return crow::json::wvalue({ { "message", "Hello, World!" }, {"message2", "Hello, World.. Again!"} });
29+
});
30+
31+
CROW_ROUTE(app, "/custom")
32+
([]() {
33+
return a();
34+
});
35+
36+
CROW_ROUTE(app, "/hello/<int>").methods(crow::HTTPMethod::POST)([&values](int count) {
37+
values.push_back(count);
38+
return crow::response(std::to_string(count));
39+
});
40+
41+
CROW_ROUTE(app, "/hello/").methods(crow::HTTPMethod::GET)([&values]() {
42+
crow::json::wvalue returnValue;
43+
returnValue["values"] = values;
44+
return returnValue;
45+
});
46+
47+
app.port(port).run();
48+
return 0;
49+
}

0 commit comments

Comments
 (0)