doompanning/demo/rest
oxmox 17f68cf8fe Squashed 'external/nng/' content from commit 169221da
git-subtree-dir: external/nng
git-subtree-split: 169221da8d53b2ca4fda76f894bee8505887a7c6
2023-02-03 21:18:59 +01:00
..
CMakeLists.txt Squashed 'external/nng/' content from commit 169221da 2023-02-03 21:18:59 +01:00
README.adoc Squashed 'external/nng/' content from commit 169221da 2023-02-03 21:18:59 +01:00
server.c Squashed 'external/nng/' content from commit 169221da 2023-02-03 21:18:59 +01: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 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
----