Skip to content

It's a simple API for CRUD && Searching Operations by using Node.js && Express && HMVC Pattern

Notifications You must be signed in to change notification settings

norhan22/Schools_API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Schools API

is a zero-dependency module that loads environment variables from a .env file into process.env




MVC

  • MVC is short for Model, View, and Controller.
  • It's an architectural pattern that separates an application into three main logical components Model , view and controller
    • Model that part of the application that ( handles || stores )** data** and its related logic
    • View that part of the application that represent the presentation of data (UI components).
    • Controller is that part of the application that handles the user interaction


Example from daily life :

    View = You
    Waiter = Controller
    Cook = Model
    Refrigerator = Data

So, to sum it up:

  • Model is data part.
  • View is User Interface part.
  • Controller is request-response handler.

Node mvc project structure :

  • routes folder, which will serve as controllers.
  • models folder, in which we have a data model.
  • views folder, which have our views



resources:





HMVC

  • It's short for Hierarchical Model View Controller
  • Separate the app into Modules with MVC pattern

Resources :





  • You can create chainable route handlers for a route path by using app.route().

    • single location,
    • creating modular routes is helpful
    • as is reducing redundancy and typos.
  • For more information about routes, see: Router() documentation.

example of chained route handlers ( route : /api/schools )

  const
    express = require('express'),
    app = express()
    resource = '/api/schools'

  // chained route
  app.route(`${resource}`)
    // Get && search All Schools
    .get(schoolController.crud.getSchools)
    // add school
    .post(schoolController.crud.addSchool)

  • express.Router class for creating modular, mountable and chained route handlers
  • A router object is an isolated instance of middleware and routes.

example of express route handlers ( route : /api/schools )

  const
    express = require('express'),
    app = express()
    router = express.Router()
    resource = '/api/schools'

  // chained route
  router.route(`${resource}`)
    // Get && search All Schools
    .get(schoolController.crud.getSchools)
    // add school
    .post(schoolController.crud.addSchool)




Middleware

  • It's basically a function which accepts request and response objects and a next() function.

      app.use(function middleware1(req, res, next) {
        console.log('Middleware 1')
      next();
      });
    

About

It's a simple API for CRUD && Searching Operations by using Node.js && Express && HMVC Pattern

Resources

Stars

Watchers

Forks