Nodejs app that has an API to handle metric logs. To see the live DEMO, please go to the section 4.2.1 under this document.
The API has two methods
URL: /metric/{key}
Body:
{
"value": 400
}
Response:
{}
This endpoint stores a value for the corresponding metric.
URL: /metric/{key}/sum
Response:
{
"value": 400
}
This endpoint retrieves the last hour aggregated sum for the corresponding key.
Important:
Whenever you try to get the sum from a metric that hasn't been logged yet, the API will return 0.
If everything works successfully, the API returns a HTTP Status 200
If any of the parameters is incorrect, the API returns a HTTP Status 400
If something wrong happen at the server, the API returns a HTTP Status 500
If you make a request using an unsupported HTTP method, the API returns a HTTP Status 405.
This example uses Nodejs, Typescript, Express and Docker.
There are two ways of executing the project.
- Microservice way
- Lambda way
For the sake of demonstration, I added an additional layer that allows you to deploy the code as a lambda function using Netlify, but you can run it as a Docker container as well.
In order to run this project locally, you need the following technologies/tools installed.
-
Make (Optional): This is installed by default in Linux and MacOS.
Execute the following commands at the project's root folder.
- Run it using Make.
$ make start
OR
- Run it using docker-compose command.
$ docker-compose up -d
In order to deploy this lambda to Netlify, you must execute the following command
$ netlify deploy
Follow the instructions to connect it to your Netlify's account.
Try executing this on your terminal:
curl \
--header "Content-Type: application/json" \
--request POST \
--data '{"value":"20"}' \
https://node-logging.netlify.app/.netlify/functions/lambda/test