1.3.4 • Published 2 years ago

yasui v1.3.4

Weekly downloads
27
License
ISC
Repository
github
Last release
2 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.

Browse the src/examples folder to get an example of a simple server using the basic features of Yasui.

 

Configuration

createServer and createApp takes a configuration object with the following parameters:

ParameterDescription
controllersAn array containing your controllers (classes using the @Controller decorator).
middlewaresAn array containing your application level middlewares (classes using the @Middleware decorator).
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.

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.

The parameters of your endpoint can be decorated with the following: @Res, @Req, @Next, to reflect express arguments, or with @Param, @Body, @Query, @Header to select a specific parameter from the query, or a subset of it ; they can take the name of the desired parameter as a parameter, in which case they will return the whole set.

@Logger also provides a query-specific timed logger service.

Example

import express from 'express';
import { Get, Controller, Res, Param } from 'yasui';

@Controller('/')
export class MyController {

    @Get('/:name')
    private hello(
        @Param('name') name: string,
        @Res() res: express.Response
    ): void {
        res.status(200).json({ message: `Hello ${name}!` });
    }
}

 

Middlewares

Yasui provides also decorators to define your middlewares like controllers and use its at application, controller, or endpoint level.

The Middleware decorator does not take parameter.

The parameters of your middleware can be decorated with the same decorators as controller endpoints.

Your middleware must obligatorily implement an use() method, which will define the execution function of it.

Example

import express from 'express';
import { logger, Middleware, Param, Next } from '..';

@Middleware()
export class HelloMiddleware {
    use(
        @Param('name') name: string,
        @Next() next: express.NextFunction
    ): void {
        logger.log(`Hello ${name}`);
        next();
    }
}
@Controller('/', HelloMiddleware)
// [...]
@Get('/:name', HelloMiddleware)
// [...]

 

Dependency injections

Not yet documented.

See src/examples folder for examples.

1.3.4

2 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.8

3 years ago

0.2.5

3 years ago

0.2.0

3 years ago

0.1.10

3 years ago

0.1.0

3 years ago

0.4.2

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago