Thursday, 5 July 2018

Dinoloop - REST API Expressjs library for Nodejs powered by Typescript with OOP and SOLID principles

Dinoloop is an ExpressJs library, completely written in Typescript project designed to build REST APIs. Dinoloop adds syntactic sugar to expressjs enabling C#/Java programmers to easily switch to Nodejs with zero or less learning curve. You can reuse OOP, SOLID principles, Controllers, Services, Well-Proven OOP Design Patterns in Nodejs while developing REST APIs using Dinoloop.Prerequisitesnode 8.10.x or higherexpress 4.x.x or higherGetting StartedDinoloop has been designed from the start for gradual adoption and you can use as little or as much dinoloop as you need. Perhaps you only want to develop some "REST APIs" using dinoloop and other REST APIs can be developed using expressjs. In this section, we will show how to create dinoloop REST API to an existing or newly created express app.Step 1: Add HomeController (file: home.controller.ts)import { ApiController, Controller, HttpGet, SendsResponse } from 'dinoloop'; @Controller('/home') export class HomeController extends ApiController { @HttpGet('/get') get(): string { return 'Hello World!'; } // Value injection framework, injects segments into action-args @SendsResponse() @HttpGet('/download/file/:id') name(id: string): void { // this.request is express.request object let headers = this.request.headers; // this.response is express.response object this.response.download('file.txt'); } } Step 2: Mount dinoloop and bind to express instance (file: app.ts)import { Dino } from 'dinoloop'; import express = require('express'); const app = express(); // Dino requires express instance and base-Uri const dino = new Dino(app, '/api'); // Dino requires express router too dino.useRouter(() => express.Router()); // Register controller dino.registerController(HomeController); // Bind dino to express dino.bind(); // These are your normal express endpoints app.get('/home', (req, res, next) => { res.status(200).json('Hello World!'); }); app.get('/about', (req, res, next) => { res.status(200).json('Hello World!'); }); // Start your express app app.listen(8088, () => console.log('Server started on port 8088')); Dinoloop is mounted on /api and all of the controller routes/endpoints which are registered with dinoloop are also mounted on /api. Dinoloop will handle /api/home/get requests since it is mounted on /api. The other end points /home and /about which are created by expressjs are not handled by dinoloop, this way you can slowly migrate your existing express app to dinoloop or you can start writing your new REST APIs using dinoloop with express.FeaturesSuper easy set-up, git clone your taste of starter project and start building right away.Supports express middlewares, completely express compatible.Heavily influenced by MVC pattern.Configurable Dependency injection support, Works with and Without DI.Proper isolation of controllers and services.Middlewares, ActionFilters, ExceptionFilters, ResultFilters at controller level.Robust Sync/Async middlewares to handle es6 async-await pattern.UserIdentity principal across request.MotivationTypescript (Javascript now) supports object oriented programming, these features are great with SOLID design principles. Dinoloop has simple motto, to apply SOLID principles and reuse similar coding skills of Java and C# in Nodejs.PhilosophyDinoloop lets user to freely upgrade/downgrade expressjs. Installing dinoloop won't install express. You can install your own version of express. All you have to provide is express app, express router instance to dinoloop.Questions raised by our communityDinoloop looks pretty new, Should I use it?As a contributor, we would definitely request you to give it a try (May be your personal or mini sized projects). The way expressjs does not abstract you from node, Dinoloop does not abstract you from expressjs. You are free to use/mix node, express and dinoloop in your development. Indeed 99% of code you write would be purely node, typescript and express. Dinoloop is a library at server-side (like Reactjs, we love what Reactjs does at client-side). You can either develop entire application in Dinoloop or part of it or gradually migrate expressjs to Dinoloop. The first principle of Dinoloop is to provide architecture shift to developers and not to create a complete huge framework because we do not want our developers to run into issues because of dinoloop, we love and support pluggable architecture.Typescript for Node, Seems pretty new?We love Typescript and it provides great tooling to develop enterprise applications. Angular promotes typescript and now it is hard to imagine npm packages without types. If you are a lover of angular (like us), we highly suggest you to use Dinoloop to maintain single Typescript codebase for MEAN application.Reference Links:Dinoloop github repositoryDinoloop wikiI appreciate your time on reading this article, Give it a try for your personal projects and let me know your valuables thoughts on it. Pull Requests and Contributors are always welcome :)

Submitted July 05, 2018 at 09:05PM by dinoloop

No comments:

Post a Comment