/metric-service

Metric and reporting service

Primary LanguageTypeScript

Metric logging and reporting service

Problem

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.

APIs

POST metric

Request
POST /metric/{key}
{
"value": 30
}
Response (200)
{}

GET metric sum

Returns the sum of all metrics reported for this key over the past hour.

Request
GET /metric/{key}/sum
Response (200)
{
"value": 400
}

Screenshots of the API working

base_url = localhost:3333

POST base_url/metric/active_users (create a metric)  POST

GET base_url/metric/all (for testing the sum API)  GET

GET base_url/metric/active_users/sum (sum all metric from last hour)  GET

Installation and Setup Instructions

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