mesytec-mnode/demo/rest
Florian Lüke 3a3a557efe Squashed 'external/nng/' content from commit c5e9d8ac
git-subtree-dir: external/nng
git-subtree-split: c5e9d8acfc226418dedcf2e34a617bffae043ff6
2023-06-27 18:01:51 +02:00
..
CMakeLists.txt Squashed 'external/nng/' content from commit c5e9d8ac 2023-06-27 18:01:51 +02:00
README.adoc Squashed 'external/nng/' content from commit c5e9d8ac 2023-06-27 18:01:51 +02:00
server.c Squashed 'external/nng/' content from commit c5e9d8ac 2023-06-27 18:01:51 +02:00

= REST API Gateway demo

This is a somewhat contrived demonstration, but may be useful
in a pattern for solving real world problems.

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,
  the reply is redirected back to the server.  (For the purposes of the
  demonstration, our server just performs ROT13 on input.)

. REP server (implemented in the same program using inproc, for demonstration
  purposes. In a real world scenario this might instead go to another
  process on another computer.)

[source, bash]
----
% env PORT=8888  # default
% ./rest-server &
% curl -d ABC http://127.0.0.1:8888/api/rest/rot13; echo
NOP
% curl -d NOP 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
----