- Getting Started
- Create new Student API using MongoDB
- Create new Student API using SqlServer
- All Commands
- Configuration
-
Clone the repo in your working directory
-
Run service with development environment
yarn start
We will follow the instructions by adding a Student
registartion API which will connect to mongodb
-
Create mongodb collection model under
api\models
folder -
Import model created in
step(1)
inapi\models\index
-
Add new validator file under
api\validators\student.validators.js
to implement request validation usingJoi
a. Export a method named as
validateRegisterStudent
-
Add new controller under
api\controllers
folder with file name asstudent.controller.js
a. Export a method named as
registerStudent
b. Before processing request, validate request object by importing validator method created in
step (3)
c. If valid request, process request with required logic
-
Define API route path for new method under
api\app.constants.js
as belowexports.studentController = { routeName: '/students', routeMethods: { registerStudentRoute: '/registerStudent', }, };
-
Create new route file under
api\routes\student.route.js
. Attach route path(defined instep-5
) and controller method(defined instep-4
) as belowimport express from 'express';
import studentCtrl from '../controllers/student.controller';
import appConstants from '../app.constants';
const router = express.Router();
router.route(appConstants.studentController.routeMethods.registerStudentRoute).post(studentCtrl.registerStudent);
-
Import route file(defined in
step-6
) inapi\routes\index.route.js
file and attach routeimport studentRoutes from './student.route';
router.use(appConstants.studentController.routeName, studentRoutes);
We will follow the instructions by adding a Student
registartion API which will connect to mongodb
-
Add new
student.dal.js
file underapi\dal
foldera. Export a method named as
registerStudent
-
Add new validator file under
api\validators\student.validators.js
to implement request validation usingJoi
a. Export a method named as
validateRegisterStudent
-
Add new controller under
api\controllers
folder with file name asstudent.controller.js
a. Export a method named as
registerStudent
b. Before processing request, validate request object by importing validator method created in
step (3)
c. If valid request, process request with required logic by consuming method created in
step-1
-
Define API route path for new method under
api\app.constants.js
as belowexports.studentController = { routeName: '/students', routeMethods: { registerStudentRoute: '/registerStudent', }, };
-
Create new route file under
api\routes\student.route.js
. Attach route path(defined instep-5
) and controller method(defined instep-4
) as belowimport express from 'express';
import studentCtrl from '../controllers/student.controller';
import appConstants from '../app.constants';
const router = express.Router();
router.route(appConstants.studentController.routeMethods.registerStudentRoute).post(studentCtrl.registerStudent);
-
Import route file(defined in
step-6
) inapi\routes\index.route.js
file and attach routeimport studentRoutes from './student.route';
router.use(appConstants.studentController.routeName, studentRoutes);
- Start service in development environment
yarn run start
- Transpile service from ES6 to ES5 for devQA Or prodQA or prodRelease environments
yarn run build
- Start/Stop service in
devQA
environment. Naviagate todist
folder created in step (2) and execute below commands to start/stop serviceyarn run startdevqa yarn run stopdevqa
- Start/Stop service in
prodQA
environment Naviagate todist
folder created in step (2) and execute below commands to start/stop serviceyarn run startprodqa yarn run stopprodqa
- Start/Stop service in
prodRelease
environment Naviagate todist
folder created in step (2) and execute below commands to start/stop serviceyarn run startprodrelease yarn run stopprodrelease
- Get outdated packages information
yarn run getoutdatedpackages
- There is different configuration file for every environment which can be found under
config
folder. - Below attributes can be configured in every
config
file- port - In which port we are interested to start service
- secureCommunication - Whether to use SSL for service or not
- mongoConnectionString - MongoDB connection string
- sqlConnectionString - SQL Server connection string