Code Monkey home page Code Monkey logo

micro-template's Introduction

micro-template

Core concepts

If the web application accepts the request and returns the response, it is reasonable to express it with a function. Indeed, applications are arbitrarily complex. But they accept the request and return the response, so at the abstract level, it is a function.

A router is also a function that accepts a request, determines the necessary handler, and returns a response.

A request handler is a function that accepts a request and returns a response. The middleware technique is best suited to add intermediate logic, such as query parameters, sessions, cookies, access rights.

Middleware is also a function that accepts a handler function and returns a new handler with augmented logic. Also, each middleware can break the chain, depending on the circumstances. Pattern decorator is a special case of Middleware. Therefore, our middleware is a bit different from those that are taken in Express.

Each heavy abstraction will replace by a function. This is convenient because, unlike classes, functions are composable.

Core Components

Application Server — lib/server.js

Manages the lifecycle of the HTTP server. There are two functions that control the lifecycle of the application, these are the startServer and the stopServer functions respectively.

Application Handler — lib/app.js

Responsible for aggregating all the routes and wrapping them with any necessary middleware.

Application Middleware — lib/middleware

This folder is reserved for any wrapper functions that are used to modify the requests and responses. The main purpose of the middleware is to provide a central place for handling common tasks such as request validation. Middleware is just a wrapper (decorator) for the request handler.

Application Routes — lib/routes

Aggregates the routes for handling all the requests to our application. All routes handlers are there.

Application Api — api/

Core functionality

Template structure

.
├── LICENSE
├── README.md
├── lib
│   ├── api
│   │   └── books
│   │       └── index.js
│   ├── app.js
│   ├── config
│   │   ├── index.js
│   │   ├── schema.js
│   │   └── validate.js
│   ├── logger.js
│   ├── middleware
│   │   ├── __test__
│   │   │   └── wrap-json-body.unit.test.js
│   │   ├── index.js
│   │   ├── wrap-api-handler.js
│   │   ├── wrap-catch-error.js
│   │   └── wrap-json-body.js
│   ├── routes
│   │   ├── health-check.js
│   │   ├── index.js
│   │   └── not-found.js
│   ├── server.js
│   └── util
│       └── fkit
│           └── index.js
├── package-lock.json
└── package.json

Usage

  • Clone the repository
git clone https://github.com/igat64/micro-template.git
  • Install the dependencies
npm install
  • Start the microservice
npm start
  • Start in Development mode
npm run start:dev

micro-template's People

Contributors

igat64 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.