1.0.7 • Published 7 years ago

hinos-requestmatcher v1.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

hi-requestmatcher

A plugin cast type for request as query, params, body before get data in controller hinos

Install

npm i hinos-requestmatcher -S

Examples

Typescript

File controller

import { GET, POST, PUT, DELETE, HEAD } from 'hinos-route';
import { BODYPARSER } from 'hinos-bodyparser';
import { MATCHER } from 'hinos-requestmatcher';

export default class ChartController {

    @POST('/chart/:id')
    @BODYPARSER() // Parse body first
    @MATCHER({ // Cast data type
        params: {
            id: Mongo.uuid    
        }, 
        body: {
            name: String,
            des: String,
            id: id => +id; // Customize parser, can use async, await
        }
    })
    static async add({
        params, // get after parse and match
		body // get after parse and match
	}) {
        const rs: Chart = await ChartService.insert(body);
        return rs;
    }
}
1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago