Skip to content

Commit a3064b2

Browse files
committed
added small example for using crow
1 parent fdb7a7f commit a3064b2

4 files changed

Lines changed: 61 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_BOOST_BEAST)
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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
crow::json::wvalue returnValue({ { "message", "Hello, World!" } });
29+
returnValue["message2"] = "Hello, World.. Again!";
30+
return returnValue;
31+
});
32+
33+
CROW_ROUTE(app, "/custom")
34+
([] {
35+
return a();
36+
});
37+
38+
CROW_ROUTE(app, "/hello/<int>").methods(crow::HTTPMethod::POST)([&values](int count) {
39+
values.push_back(count);
40+
return crow::response(std::to_string(count));
41+
});
42+
43+
CROW_ROUTE(app, "/hello/").methods(crow::HTTPMethod::GET)([&values]() {
44+
crow::json::wvalue returnValue;
45+
returnValue["values"] = values;
46+
return returnValue;
47+
});
48+
49+
app.port(port).run();
50+
return 0;
51+
}

0 commit comments

Comments
 (0)