1.0.0 • Published 3 years ago

sriashika_helloworld-rest-api v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

Welcome to my Hello World API

A quick walkthrough over the used npm commands

S.NoList of CommandsDescription
1npm initThis command initializes a package.json file with all the settings that the creator wishes to include.
2Configure package.jsonThe 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...-
3npm installOnce 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.
4npm i -g jestThis command enables the user to install jest framework globally for unit testing 7 code coverage.
5npm i -g jsdocThis command enables the user to install jsdoc tool globally for documentating his/her code.
6npm i -g jest-html-reporters --save-devThis command enables the user to install the html reporter globally for generating test reports in the form of an html page. *Refer to NOTE.
7npm i -g eslintThis command enables the user to install the eslint tool globally for linting purposes. *Refer to NOTE.
8npm i -g supertestApart from jest, we've added the support of supertest for this helloWorldAPI testing. This command enables us to install supertest globally.
9npm run lintAccording to package.json configuration, this command will fix all fixable possible errors in all .js files in the src & tests directory.
10npm run docAccording to package.json configuration, this command will produce the documentation reports for all .js files.
11npm testThis command will run the tests for desired project along with code coverage.
12npm publishThis 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:

  1. Initializing an npm package file in the desired directory.
  2. 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.
  3. Creating a Hello World API
  4. 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"
  5. Document the API code using jsdoc && swagger-jsdoc
  6. Configure the jsdoc & swagger-jsdoc JSON files accordingly.
    • Generate HTML reports for tests, code coverage, documentation & swaggerUI.

Know More About...

  1. GET / routes
    1. GET /
      • 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 or Not found
    2. 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
    3. 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