This repository is a golang web service that exposes REST HTTP APIs to perform math operations like min, max, average, median, percentile against the list of numbers. It uses Gorilla Mux package to implement a request router and dispatcher for matching incoming requests to their handlers. The web service can be connected through port 8080
on localhost
.
- Method:
POST
- URI:
/min
- Content-Type:
application/json
- Request Body:
Paramter | Description |
---|---|
numList |
Array of numbers |
quantifier |
Number, (how many) |
- Method:
POST
- URI:
/max
- Content-Type:
application/json
- Request Body:
Paramter | Description |
---|---|
numList |
Array of numbers |
quantifier |
Number, (how many) |
- Method:
POST
- URI:
/avg
- Content-Type:
application/json
- Request Body:
Paramter | Description |
---|---|
numList |
Array of numbers |
- Method:
POST
- URI:
/median
- Content-Type:
application/json
- Request Body:
Paramter | Description |
---|---|
numList |
Array of numbers |
- Method:
POST
- URI:
/percentile
- Content-Type:
application/json
- Request Body:
Paramter | Description |
---|---|
numList |
Array of numbers |
quantifier |
Number, (q) |
This utility assumes that it contains enough memory space to store all the resources. The percentile is calculated using Nearest-Rank method.
Before you start, please make sure you have Go installed in your system. If not, please use the following link to install Golang: https://golang.org/doc/install
Clone the git repository in your system and then cd into project root directory
$ git clone https://github.com/RashikaAggarwal/math-api-webservice.git
$ cd math-api-webservice
Build your tool by executing the following steps
$ cd application
$ go run .
The server runs on http://localhost:8080 and can be hit through any client like Postman.
This utility takes input request in the form of json body. See below examples
http://localhost:8080/min
{
"numList": [1,5,9,3,7.9],
"quantifier": 2
}
[1 3]
For example, In case of Quantifier passes greater than the length of array
Quantifier must be less than equal to the length of list of numbers.
http://localhost:8080/max
{
"numList": [1,5,9,3,7.9],
"quantifier": 2
}
[9 7.9]
For example, In case of empty quantifier
Incomplete input request parameters.
http://localhost:8080/avg
{
"numList": [1,5,9,3,7.9]
}
5.18
For example, In case of empty array of numbers
Incomplete input request parameters.
http://localhost:8080/median
{
"numList": [1,5,9,3,7.9]
}
5
For example, In case of invalid numbers of array
Invalid input request.
http://localhost:8080/percentile
{
"numList": [1,5,9,3,7.9],
"quantifier": 75
}
7.9
For example, In case of quantifier greater than 100th percentile
Quantifier must be less than equal to the 100th percentile.
This repository contains unit test cases which provide the industry standard code coverage. The test cases can be executed using following commands:
$ cd math-api-webservice/application
$ go test
To get the code coverage, use the following command:
$ go test -cover
- Handling of invalid routing requests.
- Response Body in a formatted structure
- Response codes and messages maintained in configuration file for success and failure scenarios.
- Include Logging mechanism using packages like "log" to trace the entire API call for monitoring and debugging purposes.
- Secure the APIs through tokens and authorization purposes.
- Handling of concurrent user requests.
- Deploy the application using Nginx server to balance the load and handle server crashing.
- Include Docker to deploy the application on Kubernetes cluster to handle vertical and horizontal scaling effectively.