Challenge to show a REST API which allows to create, read and modify travel information
# install dependencies
$ npm install
Copy the env.sample file to .env and fill DATABASE_URI with the connection information to a mongo
PORT=3000
DATABASE_URI=mongodb://user:pass@localhost/database
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
The challenge had the following points:
-
Migrate JSON data to a database
Solution The mongoimport tool was used as in the following script
mongoimport --host <host> --ssl -u mark -p '<pass>' --authenticationDatabase admin --db <db> --collection <collection> --drop --file <file>.json --jsonArray
-
Create a Rest API
Solution
The Next JS framework with TypeScript was used to create the REST API. NestJs made with Node.js and uses Express as HTTP Server.
-
Create the following endpoints
Check the number of total trips
Solution The endpoint showing the solution is /trips/count by the GET method
Check the number of total trips by city
Solution The endpoint showing the solution is /trips/countByCity by the GET method
Create a trip
Solution The endpoint it creates is /trips by the POST method
Update a trip
Solution The endpoint it update is /trips by the PUT method
-
Create the API documentation in Swagger
Solution Documentation with Swagger http://localhost:3000/docs/
-
Create a diagram of the developed application architecture
Solution
Function branch workflow was used
To see the solutions configure the Mongodb database and run the project in production mode on port 3000
- Author - Wilson Romero
- Twitter - @WilsonRomeroC