0.4.7 • Published 5 years ago

@sendups/yasui-sandbox v0.4.7

Weekly downloads
-
License
ISC
Repository
github
Last release
5 years ago

Yasui

Light framework using Express for Node.js applications.

(◠‿◠)やすいです!

Yasui can mean "easy" in Japanese. Yasui is meant to be easy to use, light, going to essentials only, with few dependencies. Yasui simplifies your life by providing you tools to quickly implement your controllers, middleware, endpoints, and your server. Yasui provides also complete errors management (logs and client responses) and logging service.

 

Get started

$ npm install yasui
import yasui from 'yasui';
yasui.createServer({ });

createServer will create an http server and listen it. Use yasui.createApp({ }), that return an express application, if you want to perform additional operations on it before listening the server and use your own listening method.

 

Configuration

createServer and createApp takes a configuration object that can take the following parameters:

ParameterDescription
controllersAn array containing your controllers (classes using the @Controller decorator).
middlewaresA function table of type express.RequestHandler.
environmentThe name of your environment.
portThe listening port of your server (not needed in createApp). 3000 by default
debugBoolean, display logs more provided if true, and logs all incoming requests.
apiKeyAuthentication key for your API. If provided, all requests should contain the x-api-key header.

 

Controllers

Yasui provides decorators to define your controllers and endpoints.

The Controller decorator takes in parameter the root path of its endpoints. You can also provide middlewares restricted to your controller.

The methods of your controller can be decorated with the following: @Get, @Post, @Put, @Delete, @Patch. These take in parameter the relative path of the endpoint. You can also provide middlewares restricted to your endpoint.

Example

import express from 'express';
import { Get, Controller, Post, logger } from 'yasui';

export abstract class MyMiddleware {
    public static log(req, res, next): void {
        console.log('Hello world !')
        next();
    }
}

@Controller('/tests')
export class MyController {
    @Get('/', MyMiddleware.log)
    private hello(req, res): void {
        res.status(200).json({ message: 'Hello world !' });
    }
}

See src/examples folder for more details.

0.4.7

5 years ago

0.4.6

5 years ago

0.4.5

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago