doompanning/external/nng/demo/rest
oxmox b3f1d5611f git subtree add --squash -P external/nng https://github.com/nanomsg/nng.git v1.8.0
Merge commit '7063e2102e655079574d6644b323f28f48685c5a' as 'external/nng'
2024-12-18 18:33:08 +01:00
..
CMakeLists.txt git subtree add --squash -P external/nng https://github.com/nanomsg/nng.git v1.8.0 2024-12-18 18:33:08 +01:00
README.adoc git subtree add --squash -P external/nng https://github.com/nanomsg/nng.git v1.8.0 2024-12-18 18:33:08 +01:00
server.c git subtree add --squash -P external/nng https://github.com/nanomsg/nng.git v1.8.0 2024-12-18 18:33:08 +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 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
----