Skip to content

REST API built Serverless, Typescript, Node, MongoDB, Redis, Jest, AWS Lambda, Docker, etc

Notifications You must be signed in to change notification settings

web2solutions/arithmetic-calculator-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arithmetic Calculator API

This is a simple REST API built as coding challenge made for TrueNorth.

See the requirement's list.

CircleCI status:

CircleCI main

CircleCI dev

Coverage

codecov

Stack

  • Node.js
  • TypeScript
  • MongoDB and Mongo Atlas as Database
  • Redis and Redis Labs as Cache layer
  • Jest
  • AWS lambda
  • Eslint
  • Docker
  • serverless and serverless-offline

Preparing the development environment using your current NodeJS installation

You need to install the project first:

npm install

Before running the API, you must have Mongo and Redis installed first.

You can manually install them, or, you can use docker to install it by running:

npm run docker:compose:daemon

Testing using local Mongo and Redis services

You probably want to run the current test suite implementation:

npm test:dev 

Running the application on local environment

It is recommended to set the NODE_ENV env var value to 'dev'

export NODE_ENV=dev

Add some users and operations to the database:

npm run data:seed:dev

An then you can start the dev environment by running:

npm run local:start:dev

You can do login as admin user through the API by using curl:

curl -X POST http://localhost:3000/dev/users/login -H "Content-Type: application/json" -d '{"username": "admin@admin.com", "password": "123456"}'  

Managing Mongo and Redis using Docker

npm run docker:compose:daemon

Stop Docker environment

npm run docker:stop

Restart Docker environment

npm run docker:restart
npm run docker:clean

Clean Docker environment

npm run docker:clean

Testing on CI

When running on CI, the API connects to Mongo Atlas and Redis Labs.

Please make sure you have the proper accounts.

You can create for free, both accounts at https://redis.com/try-free/ and https://www.mongodb.com/cloud/atlas/register .

Setup the following env vars on CI platform:

  NODE_ENV="ci"
  
  CODECOV_TOKEN="xxxxxxx" # for codecov service
  
  TOKEN_KEY="mysecret" # for jwt token

  REDIS_HOST_LABS="redis-16050.c10.us-east-1-2.ec2.cloud.redislabs.com"
  REDIS_PASSWORD_LABS="........"
  REDIS_PORT_LABS=16050

  MONGO_ATLAS_URL="mongodb+srv://username:password@cluster0.mie7dav.mongodb.net/?retryWrites=true&w=majority"
  MONGO_DATABASE="arithmetic_calculator_api"

Run the default npm test command to run the test suite for CI.

npm test

Deploy

Environment Config

By default the application will assume the following stage names and config files:

  • test
  • prod
  • stg

Each one of those will required a related config file:

  • ./config/.env.test
  • ./config/.env.prod
  • ./config/.env.stg

Use the following template:

TOKEN_KEY=mysecret

REDIS_HOST_LABS="redis-16050.c10.us-east-1-2.ec2.cloud.redislabs.com"
REDIS_PASSWORD_LABS="password"
REDIS_PORT_LABS=16050

MONGO_ATLAS_URL="mongodb+srv://username:password@cluster0.mie7dav.mongodb.net/?retryWrites=true&w=majority"
MONGO_DATABASE="arithmetic_calculator_api"

Deploy on AWS, simply run

$ npm run deploy

# or

$ serverless deploy

Usage

send an HTTP request directly to the endpoint using a tool like curl

curl https://je6x0x8fa6.execute-api.us-east-2.amazonaws.com/test/users

Scaling

By default, AWS Lambda limits the total concurrent executions across all functions within a given region to 1000. The default limit is a safety limit that protects you from costs due to potential runaway or recursive functions during initial development and testing. To increase this limit above the default, follow the steps in To request a limit increase for concurrent executions.

Project Tech Debits

  1. Improve code coverage
  2. Implement test suite for unit testing.
  3. Implement test suite for e2e testing.
  4. Adopt the Data Repository Pattern.
  5. 100% Ensure the SOLID principles.
  6. Implement API documentation - swagger OAS.
  7. APM with datadog - custom error classes in 2 levels: service and controller

About

REST API built Serverless, Typescript, Node, MongoDB, Redis, Jest, AWS Lambda, Docker, etc

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages