fizz-buzz REST server
A simple fizz-buzz REST server with statistics.
Usage of fizzbuzz:
--port int Set the port on which the fizz-buzz server should listen (default 80)
--timeout int Set the maximum duration in seconds before timing out execution of fizz-buzz (default 30)
Endpoints
/
GET Basic health check, always returns 200
if the server is running.
/api/v1/fizz-buzz
GET This endpoint returns a JSON list of strings with numbers from 1 to limit
, where:
all multiples of int1
are replaced by str1
, all multiples of int2
are replaced
by str2
, all multiples of int1
and int2
are replaced by str1str2
.
It accepts the following query parameters:
int1
- required, non-zero integerint2
- required, non-zero integerlimit
- required, non-zero positive integerstr1
- a stringstr2
- a string
Example (200 OK)
/api/v1/fizz-buzz?int1=2&int2=3&limit=10&str1=foo&str2=bar
["1","foo","bar","foo","5","foobar","7","foo","bar","foo"]
Example (400 Bad Request)
/api/v1/fizz-buzz?int1=2&int2=0&limit=10&str1=foo&str2=bar
{"message":"zero int1 and/or int2"}
Example (503 Service Unavailable)
{"message":"context deadline exceeded"}
/api/v1/stats
GET This endpoint returns a JSON object with the parameters of the most frequent request and the number of occurrences of this request.
Example (200 OK)
/api/v1/stats
{"count":10,"int1":"2","int2":"3","limit":"10","str1":"foo","str2":"bar"}
However, one may provide its own data source implementation by implementing the
stats.Statitistics
interface. Suitable data sources could be either No-SQL or SQL.
For the latter, the implementer will have to make sure the requests' parameters do not
lead to SQL injection (e.g., str1
equals DROP TABLE foo;
).
Development
Requirements
- Go >= 1.16
- golangci-lint >= 1.39
- A linux-like terminal (ideally)
Makefile commands
make fmt
- Shortcut forgo fmt
andgo mod tidy
make lint
- Runs lintersmake tests
- Runs testsmake todos
- Shows TODOsmake godoc
- Runs a local webserver for godocmake run
- Runs the application (PORT
andTIMEOUT
are available as variables, i.e,make run PORT=80 TIMEOUT=30
)make build
- Builds the application (VERSION
is available as variable, i.e,make build VERSION=foo
)