helloworld-api-custom v1.0.0
helloworld-api-custom
A simple REST API to display Hello World and Hello <Name>, welcome to SysCloud! message.
Description
This is a simple hello world API which has get requests for displaying Hello World message. An API (Application Programming Interface) is a set of features and rules that exist inside a software program (the application) enabling interaction with it through software - as opposed to a human user interface. The API can be seen as a simple contract (the interface) between the application offering it and other items, such as third-party software or hardware.
In Web development, an API is generally a set of code features (e.g. methods, properties, events, and URLs) that a developer can use in their apps for interacting with components of a user's web browser, or other software/hardware on the user's computer, or third-party websites and services. This Is a simple Hello World API. This API supports GET Routes. It displays "Hello World!" on the root endpoint and "Hello <Name>, welcome to Syscloud!" if a name parameter is requested.
This has been built using NEST.js JavaScript web framework on top of node.js. Nest (NestJS) is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with and fully supports TypeScript (yet still enables developers to code in pure JavaScript) and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).
Under the hood, Nest makes use of robust HTTP Server frameworks like Express (the default) and optionally can be configured to use Fastify as well!
Nest provides a level of abstraction above these common Node.js frameworks (Express/Fastify), but also exposes their APIs directly to the developer. This gives developers the freedom to use the myriad of third-party modules which are available for the underlying platform.
Prerequisites
Make sure that Node.js (>= 10.13.0) is installed for your operating system.
Install nest.js
# install from npmjs public repository $ npm install -g @nestjs/cli
Installation
# install from aws repository
$ npm install helloworld-api-custom@1.0.0
Running the app
# development
$ cd node_modules/helloworld-api-custom
$ npm run start
# watch mode
$ cd node_modules/helloworld-api-custom
$ npm run start:dev
# production mode
$ cd node_modules/helloworld-api-custom
$ npm run start:prod
Sending requests using cmd or bash
# sending GET /hello request
$ curl -X GET "http://localhost:3000/hello" -H "accept: */*"
# returns: Hello World!
# sending GET /hello-name/{name} request
$ curl -X GET "http://localhost:3000/hello-name/John" -H "accept: */*"
# returns: Hello John, welcome to Syscloud!
Sending requests using Postman
Make sure you have Postman installed or install it from here for your operating system.
Execute the following endpoints by entering them in the URI field, choosing the correct method and hitting Send button. The response will be available below.
sending GET /hello request
http://localhost:3000/hello returns: Hello World!
sending GET /hello-name/{name} request
http://localhost:3000/hello-name/John returns: Hello John, welcome to Syscloud!
Test
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
Test using Swagger UI
Go to the link: http:localhost:3000/swagger to view the Swagger UI
sending GET /hello request
hello > GET /hello > Try it out > Execute
returns: Hello World!
sending GET /hello-name/{name} request
hello-name > GET /hello-name/{name} > Try it out > Enter name > Execute
returns: Hello John, welcome to Syscloud!
Linting
# package linting
$ npm run lint
Documentation
Compodoc installation
# install compodoc $ npm install --save-dev compodoc
Document generation
# generate package documentation $ npm run compodoc
License
UNLICENSED
4 years ago