Skip to content

Latest commit

 

History

History
 
 

rest

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

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:

  1. 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.)

  2. 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.)

% 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.

% mkdir build
% cd build
% cmake -G Ninja ..
% ninja

Alternatively, you can go old-school. Here’s the simplest option for Linux:

% cc server.c -o rest-server -I /usr/local/include -lnng