Skip to content
A Express and Typescript REST Service Template.
TypeScript JavaScript Other
Branch: develop
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
__test__ [PLUGIN ENGINE] Added Plugin Decorator Oct 15, 2019
benchmark
classes [PLUGIN ENGINE] Added Plugin Decorator Oct 14, 2019
decorators [CORE] Publish Tooling Oct 18, 2019
docs
exceptions
helpers [REFACTORING] Improve Code Aug 20, 2019
libs
services
tasks
.editorconfig
.gitignore
.npmignore
.nycrc
.prettierrc
.travis.yml [BADGES] Added Test Coverage on Code Climate Aug 6, 2019
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE [INITIAL] Initialize Commit Feb 27, 2019
README.md [DOCUMENTATION] Added Logo Sep 15, 2019
banner.png
gulpfile.js
jest.config.js
jsdocs.json
logo.png
package.json
tsconfig.json
tslint.json

README.md

Expressive Tea

npm (scoped) Known Vulnerabilities Build Status codecov Maintainability npm GitHub issues GitHub FOSSA Status

Expressive Tea

A Typescript library to create RESTful Services.

Description

Expressive Tea is a simple library which allow to generate RESTful services with Typescript over Expressjs.

Features

  • Server Initialization and Configurations with ability to setup server through server stages.
  • Declare Server Middlewares configuration as hard or soft dependency at server level.
  • Declarative Modules to allow create modular RESTful Servers.
  • Dependency Injection on controllers as providers with InversifyJs.
  • Declarative Router on Controllers.
  • Declarative Verbs and Middlewares under module and verb level.
  • Declarative Exceptions for a better Error Handling.
  • Can declare models depending on your flavor, we recommend Mongoose or Sequelize flavors.

Motivation

The main idea is help developers to generate a RESTful service quick and modulable through descriptive decorators and settings on top of ExpressJS. Expressive Tea is a clean, simple and descriptive mini framework which allow create REST services quickly saving time with the creation of routers and other express components with a clean, descriptive decorator.

Installation

npm i --save @zerooneit/expressive-tea

Important! Expressive Tea requires Node >= 6, Express >= 4, TypeScript >= 2.0 and the experimentalDecorators, lib compilation options in your tsconfig.json with the next configuration.

{
  "compilerOptions": {
    "baseUrl": ".",
    "sourceMap": true,
    "noEmit": false,
    "noImplicitAny": false,
    "target": "es6",
    "lib": [
      "es6",
      "dom"
    ],
    "types": [
      "reflect-metadata"
    ],
    "module": "commonjs",
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "declaration": true
  },
  "include": [
    "node_modules/@zerooneit/expressive-tea"
  ]
}

Examples

You can looking into our simple example here.

Quick Start

Boot Stages

The Application internally is ordering the plugs on the next order:

BOOT_DEPENDENCIES: This is executing when express server applications is created.

INITIALIZE_MIDDLEWARES: Global middleware initialization.

APPLICATION: This should contain express configuration or application configurations.

MODULES: This is an internal stage that is used only to create the modules.

AFTER_APPLICATION_MIDDLEWARES: Middlewares commonly used after setup the modules, commonly for error handler.

START: Can be used to add additional configuration as websocket implementation or another service.

Declare a Server

import Boot from '@zerooneit/expressive-tea/classes/Boot';
import { BOOT_STAGES } from '@zerooneit/expressive-tea/libs/constants';
import { Plug, ServerSettings, RegisterModule } from '@zerooneit/expressive-tea/decorators/server';
import RootModule from './app/Root/RootModule';
import logSetting from './config/TestPlug';

@ServerSettings({
	port: 3001
})

@Plug(BOOT_STAGES.BOOT_DEPENDENCIES, 'Log Middleware', logSetting)
class BootLoader extends Boot {
	@RegisterModule(RootModule)
	async start() {
		super.start();
	}
}

export default new BootLoader().start()
  .catch(error => console.log(error.message));

Generate A Plug Setting

The plugin always needs to be a method which is receiving express server application.

export default function testPlug(server) {
    server.use(function(req, res, next) {
        console.log('This should be executed everytime in all the endpoints');
        next();
    });
}

Generate Modules

import { Module } from '@zerooneit/expressive-tea/decorators/module';
import RootController from './controllers/RootController';
import TestService from './services/TestService';

@Module({
	controllers: [RootController], // Controllers Defined
	providers: [TestService], // Dependency Injection Providers
	mountpoint: '/' // Mountpoint Route starting from root.
})
export default class TestModule {}

Generate Controllers

import { Get, Route } from '@zerooneit/expressive-tea/decorators/router';
import { Inject } from '@zerooneit/expressive-tea/services/DependencyInjection';

@Route('/')
export default class RootController {
  /**
  * Injected Provider Instance into controller property 
  */
	@Inject('TestService')
	testService; 
  
	// Set and enpoint over module root endpoint
	@Get('/')
	async index(req, res) {
		res.send('is Working!!');
	}

	@Get('/test')
	async test(req, res) {
		res.json({success: true, message: 'this is working too'});
	}

	@Get('/test/inject')
	async testInject(req, res) {
		res.send(this.testService.test());
	}
}

Generate Injectable Service

import {injectable} from 'inversify';

@injectable()
export default class TestService {
    test() {
        return 'This is a injectable service';
    }
}}

Support

If you are experience any kind of issues we will be happy to help. You can report an issue using the issues page or the chat. You can also ask questions at Stack overflow using the expressive-tea tag.

If you want to share your thoughts with the development team or join us you will be able to do so using the official the mailing list. You can check out the wiki to learn more about Expressive Tea internals or check our documentation.

Built With

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the Apache-2.0 License - see the LICENSE file for details

FOSSA Status

Disclaimers

The banner and the logo is a derivate work Designed by Freepik

You can’t perform that action at this time.