Dummy API, Go rewrite

Published Saturday, May 16, 2015 (500 words, 3 minutes to read).

Dummy API was originally written in Lua for running on top of OpenResty. Reasons were high performance and simplicity. The most common Linux distributions do not provide packages for OpenResty in their repositories, which means that it has to be installed from source. This is straight forward, but it adds up - both in time required and extra build dependencies.

The purpose of Dummy API is to be that web application that can be rapidly installed and started when it is necessary to test API managers and web caches with a proper web application. The installation should be as simple and quick as possible.

I turned to Go and its http server, and reimplemented the Dummy API. What is really appealing about Go is that it is possible to compile an entire web application including all dependencies into one binary file. It means that the Dummy API and the web server can be compiled and distributed as one executable file:

$ sudo yum install golang
$ go build dummy-api.go
$ chmod +x dummy-api
$ ./dummy-api -host= -port=8080

It is possible to cross compile to various architectures and platforms.

I have compiled and pushed the binary version for Linux on x86_64 to the repository. The result is that the installation steps have been narrowed down to:

$ wget https://github.com/espebra/dummy-api/raw/master/dummy-api
$ chmod +x dummy-api
$ ./dummy-api

By default, it will bind to ./dummy-api -help shows the usage guide:

Usage of ./dummy-api:
  -host="": Listen host
  -maxheaderbytes=1048576: Max header bytes.
  -port=1337: Listen port
  -readtimeout=10: Read timeout in seconds
  -verbose=false: Verbose stdout.
  -writetimeout=10: Write timeout in seconds

The usage guide for web clients is shown with the help query parameter:

GET http://host/?help

Dummy API

The following request headers and query parameters will make an impact on the response.

header-delay = {int}         Delay to first header byte in ms.
body-delay = {int}           Delay to first body byte in ms.

max-age = {int}              Set the cache-control max-age value.
s-maxage = {int}             Set the cache-control s-maxage value.
must-revalidate              Set cache-control must-revalidate.
public                       Set cache-control public.
private                      Set cache-control private.
no-store                     Set cache-control no-store.
no-cache                     Set cache-control no-cache.
no-transform                 Set cache-control no-transform.

content-length               Set the content-length header, otherwise chunked
                             transfer encoding is used.
random-content = {int}       Add random string to the response of given length.
predictable-content = {int}  Add predictable string to the response of given
connection=close             Add connection=close to the response headers.
response-status = {int}      Set the response status.

The Go version is available in master, while the Lua version is available in the Lua branch. Remember to run it with an unprivileged user.