aboutsummaryrefslogtreecommitdiff
path: root/demo/rest
diff options
context:
space:
mode:
Diffstat (limited to 'demo/rest')
-rw-r--r--demo/rest/CMakeLists.txt17
-rw-r--r--demo/rest/README.adoc24
-rw-r--r--demo/rest/server.c2
3 files changed, 40 insertions, 3 deletions
diff --git a/demo/rest/CMakeLists.txt b/demo/rest/CMakeLists.txt
new file mode 100644
index 00000000..5466e3c7
--- /dev/null
+++ b/demo/rest/CMakeLists.txt
@@ -0,0 +1,17 @@
+#
+# Copyright 2018 Capitar IT Group BV <info@capitar.com>
+# Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+#
+# This software is supplied under the terms of the MIT License, a
+# copy of which should be located in the distribution where this
+# file was obtained (LICENSE.txt). A copy of the license may also be
+# found online at https://opensource.org/licenses/MIT.
+
+cmake_minimum_required (VERSION 2.8.7)
+
+project(rest)
+
+find_package(nng CONFIG REQUIRED)
+
+add_executable(rest-server server.c)
+target_link_libraries(rest-server nng::nng)
diff --git a/demo/rest/README.adoc b/demo/rest/README.adoc
index 6a363329..df3e30b0 100644
--- a/demo/rest/README.adoc
+++ b/demo/rest/README.adoc
@@ -3,7 +3,7 @@
This is a somewhat contrived demonstration, but may be useful
in a pattern for solving real world problems.
-There is a single "server" program, that does these:
+There is a single "server" (rest-server) program, that does these:
. REST API at /api/rest/rot13 - this API takes data from HTTP POST commands,
and forwards them to an NNG REQ socket. When the REQ response comes,
@@ -17,9 +17,29 @@ There is a single "server" program, that does these:
[source, bash]
----
% env PORT=8888 # default
-% ./server &
+% ./rest-server &
% curl -d ABC http://127.0.0.1:8888/api/rest/rot13; echo
NOP
% curl -d ABC http://127.0.0.1:8888/api/rest/rot13; echo
ABC
----
+
+== Compiling
+
+To build the program, we recommend CMake and Ninja-Build.
+
+[source, bash]
+----
+% mkdir build
+% cd build
+% cmake -G Ninja ..
+% ninja
+----
+
+Alternatively, you can go old-school.
+Here's the simplest option for Linux:
+
+[source, bash]
+----
+% cc server.c -o rest-server -I /usr/local/include -lnng
+----
diff --git a/demo/rest/server.c b/demo/rest/server.c
index 788fc8f1..72c24cb1 100644
--- a/demo/rest/server.c
+++ b/demo/rest/server.c
@@ -98,7 +98,7 @@ rest_free_job(rest_job *job)
if (job->msg != NULL) {
nng_msg_free(job->msg);
}
- if (job->ctx != 0) {
+ if (nng_ctx_id(job->ctx) != 0) {
nng_ctx_close(job->ctx);
}
free(job);