diff options
author | Niklas Halle <niklas@niklashalle.net> | 2020-08-23 13:57:40 +0200 |
---|---|---|
committer | Niklas Halle <niklas@niklashalle.net> | 2020-08-23 13:58:02 +0200 |
commit | 4fd77ac95998a9bff45e30a26f97e60159ad5e1d (patch) | |
tree | bd17e8f07cef20364bde750385a41d58f905d768 | |
parent | 3314a53d0cf0a135fe6f82fcc7b6f4df84f70436 (diff) | |
download | n_core-4fd77ac95998a9bff45e30a26f97e60159ad5e1d.tar.gz n_core-4fd77ac95998a9bff45e30a26f97e60159ad5e1d.zip |
added crow and basic example
-rw-r--r-- | .gitmodules | 3 | ||||
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | README.md | 7 | ||||
l--------- | include/crow | 1 | ||||
l--------- | include/crow.h | 1 | ||||
m--------- | libs/crow | 0 | ||||
-rw-r--r-- | src/main.cpp | 22 |
7 files changed, 32 insertions, 4 deletions
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..fe0f6dc --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libs/crow"] + path = libs/crow + url = git@git.niklashalle.net:crow.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c3ea9e..53d1f7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ project(N_Core DESCRIPTION "Backend of the N bot - serving JSON requests" ) -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) IF (CMAKE_VERSION VERSION_LESS "3.7.0") @@ -1,9 +1,12 @@ # N Core - the backend of N + +Build upon [crow](https://github.com/ipkn/crow) [forked](https://git.niklashalle.net/crow) to fix a deprecation in boost 1.7+ + ## N protocol ### request -Each message sent to the N core server must be valid JSON and have a `command` field. It contains the command for N to handle, sanitizied (i.e. no leading '/' or trailing username etc). +Each message sent to the N core server must be valid JSON and have a `command` field. It contains the command for N to handle, sanitized (i.e. no leading '/' or trailing username etc). The arguments field contains the remaining text just as was send to the bridge. -All messages may optionally include an `session` field. When you authorize against N core or switch to a menu, you will be returned (see next section) a session id which you can then send with this field to follow up on the inital command. +All messages may optionally include an `session` field. When you authorize against N core or switch to a menu, you will be returned (see next section) a session id which you can then send with this field to follow up on the initial command. | Field | Type | Required? | Description | |-------|------|-----------|-------------| diff --git a/include/crow b/include/crow new file mode 120000 index 0000000..f237a5a --- /dev/null +++ b/include/crow @@ -0,0 +1 @@ +../libs/crow/include/crow
\ No newline at end of file diff --git a/include/crow.h b/include/crow.h new file mode 120000 index 0000000..359d17a --- /dev/null +++ b/include/crow.h @@ -0,0 +1 @@ +../libs/crow/include/crow.h
\ No newline at end of file diff --git a/libs/crow b/libs/crow new file mode 160000 +Subproject 414f5ab444d38d4c9605d16597450282b469989 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 |