Build a metric logging and reporting service that sums metrics by time window for the most recent hour. You will build a lightweight web server that implements the two main APIs defined below.
Request
POST /metric/{key}
{
"value": 30
}
Response (200)
{}
Returns the sum of all metrics reported for this key over the past hour.
Request
GET /metric/{key}/sum
Response (200)
{
"value": 400
}
base_url = localhost:3333
POST base_url/metric/active_users (create a metric)
GET base_url/metric/all (for testing the sum API)
GET base_url/metric/active_users/sum (sum all metric from last hour)
Clone down this repository. You will need node
and npm
or yarn
installed globally on your machine.
Installation:
npm install
or
yarn
To Start Server:
npm dev:server
or
yarn dev:server
To test the API, use postman or insomnia (./assets/api you can get the requests). The server has a built-in SQLite server (it's a file that storages everything).