1.0.0 • Published 3 years ago
sriashika_helloworld-rest-api v1.0.0
Welcome to my Hello World API
A quick walkthrough over the used npm commands
S.No | List of Commands | Description |
---|---|---|
1 | npm init | This command initializes a package.json file with all the settings that the creator wishes to include. |
2 | Configure package.json | The user will be prompted to enter configuration details one after the other. Apart from the normal settings, user can also open the package.json file and add/delete configuration settings such as additional scripts or dependencies etc...- |
3 | npm install | Once the package.json file is configured, user can simply run this command to install all the dependencies, devDependencies and everything mentioned in the package.json file in one go. |
4 | npm i -g jest | This command enables the user to install jest framework globally for unit testing 7 code coverage. |
5 | npm i -g jsdoc | This command enables the user to install jsdoc tool globally for documentating his/her code. |
6 | npm i -g jest-html-reporters --save-dev | This command enables the user to install the html reporter globally for generating test reports in the form of an html page. *Refer to NOTE. |
7 | npm i -g eslint | This command enables the user to install the eslint tool globally for linting purposes. *Refer to NOTE. |
8 | npm i -g supertest | Apart from jest, we've added the support of supertest for this helloWorldAPI testing. This command enables us to install supertest globally. |
9 | npm run lint | According to package.json configuration, this command will fix all fixable possible errors in all .js files in the src & tests directory. |
10 | npm run doc | According to package.json configuration, this command will produce the documentation reports for all .js files. |
11 | npm test | This command will run the tests for desired project along with code coverage. |
12 | npm publish | This command will simply publish the package file to the npm global package registry. If already present, it will follow semantic versioning. |
*Please NOTE :
- If you're installing jest-html-reporter globally, please change the path in jest.reporters configuration to 'jest-html-reporter' in the package.json file.
- If you're installing eslint globally, please change the path in lint configuration to 'eslint' in the package.json file.
Pre-requisites:
- Knowledge of JavaScript, Node, Express & npm
- Handling JEST, JSdoc, Swagger.
- About RESTful APIs.
Phase One:
- Initializing an npm package file in the desired directory.
- Building a package.json file with all the necessary specs.
- Installing all necessary dependencies / package files
- npm
- npm is Node Package Manager.
- Basically manages terminal commands and/or installation related matters.
- node
- node is used to provide a runtime environment for JS.
- node can also be used to run the file on localhost.
- jest
- JEST, developed by Facebook, is a testing framework that's mostly used for JS.
- Unit testing & code coverage have been achieved using jest.
- ESlint
- Using ESlint for linting purposes.
- jsdoc
- Documenting our task code using jsdoc.
- swagger-jsdoc
- Documenting the api code using swagger.
- npm
- Installing all necessary dependencies / package files
- Creating a Hello World API
- Creating a Testsuite for the Hello World API
- Case 1: Check successful response statusCode: 200
- Case 2: Check successful response data: "Hello World"
- Case 3: Check successful response statusMessage: "OK"
- Case 4: Check unsuccessful response statusCode: 404
- Case 5: Check unsuccessful response data: "Error"
- Case 6: Check unsuccessful response statusMessage: "Not Found"
- Document the API code using
jsdoc
&&swagger-jsdoc
- Configure the jsdoc & swagger-jsdoc JSON files accordingly.
- Generate HTML reports for tests, code coverage, documentation & swaggerUI.
Know More About...
GET /
routesGET /
- The base path is located here
- If nothing is mentioned then this page will throw an error status code => 404
- And an error message =>
Error
orNot found
GET /helloWorld
- This is the path which the server will be listening to.
- Thie page will simply display
Hello World
- Holds a status of a successful response =>
200
- Holds status message =>
OK
GET /api-docs
- Upon implementing Swagger, the swagger documentation will appear here.
- User can perform simple CRUD operations.
- We've implemented the get operation for this API.
Author : Sriashika Addala
Date : 08/11/2020
Contact : Github profile
1.0.0
3 years ago