@zerooneit/expressive-tea
A REST API over Express and Typescript
Last updated a month ago by dresendez .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @zerooneit/expressive-tea 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.1.0                                ...           latest (a month ago)

11 Versions

  • 1.1.0                                ...           a month ago
  • 1.0.0                                ...           2 months ago
  • 0.1.1                                ...           3 months ago
  • 0.1.0                                ...           3 months ago
  • 0.0.7-RC                                ...           4 months ago
  • 0.0.6-RC1                                ...           5 months ago
  • 0.0.5-Beta                                ...           6 months ago
  • 0.0.4-Beta                                ...           6 months ago
  • 0.0.3-Alpha                                ...           7 months ago
  • 0.0.2-Alpha                                ...           8 months ago
  • 0.0.1                                ...           8 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 19
Dependencies (5)
Dev Dependencies (15)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |