Skip to content

paulotelles/cars-api

Repository files navigation

Cars API

Cognigy Challenge

This is a part of Cognigy, the objective is to build an API to create, delete, update and get Cars.

Requirements

Build a Node.JS based which uses the Express.JS framework to expose a RESTful API to manage cars.

Use:

  • modern Node.JS (node 12), ES7 / ES8 ✔️
  • use a linter ✔️
  • use the mongoose package from NPM ✔️
  • use the express package from NPM ✔️
  • use the ajv package from NPM ✔️
  • containerize the solution ✔️

Deliverables

Build a Node.JS based which uses the Express.JS framework to expose a RESTful API to manage cars. Must have an endpoint for each functionality:

  • Create a new car. ✔️
  • Read meta-data of all cars in the system. This endpoint should really only return meta-data - there is no pagination required. ✔️
  • Read the full data of an individual car. ✔️
  • Delete an individual car. ✔️
  • Updaten single properties of a single car. ✔️

Bonus task:

  • Use Typescript for your whole application and add a simple x-api-key based authentication mechanism to your application ✔️

Tech

Main Technologies:

  • NestJS - A progressive Node.js framework for building efficient, reliable and scalable server-side applications.
  • NodeJS - Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.
  • Typescript - TypeScript is JavaScript with syntax for types.
  • Express - Fast, unopinionated, minimalist web framework for Node.js.
  • Mongoose - Elegant MongoDB object modeling for Node.js
  • Docker - Build safer, share wider, run faster:
  • Github Actions - Automate your workflow from idea to production
  • Jest - Jest is a delightful JavaScript Testing Framework with a focus on simplicity.

Installation

Clone this github repository

$ npm install

First of all, create .env file in the main folder and add mongodb URI and de x-api-key as in the .env-example. (the env-example already has the MONGO_URI to use with docker-compose).

Running the app in the container

# run the application and mongodatabase
$ sudo docker-compose up
# stop the application and mongo database
$ sudo docker-compose down

Running the app localy

Install NestJs globally

$ npm install -g @nestjs/cliBasic
# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Extra

  • CI/CD: It is possible to make the CI/CD trough the pipelines configurations and utilization of Github Actions. All codes pushed to main will be deployed in Heroku if all the validations were completed.

Next steps

  • Metrics and traceability: Implement Datadog.
  • Scalability: There is just one container non scalable, for a real production it would be necessary improve this point using Kubernetes for automating deployment, scaling, and management of containerized applications
  • Security: It would be wise to implement some securities approaches, but for testing propose it was not possible.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published