@lakutata-module/api
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.29 • Public • Published

    NPM Version NODE Version Known Vulnerabilities NPM Download

    Quickstart

    Controller Example

    @Middleware(async (app,request,response)=>{
        console.log('This is controller middleware')
        request.query.middlewareTest='OK'
    })
    @Controller()
    export class TestController extends BaseController {
        @GET()
        public async getTest(@RequestId() id, @Query() query, @Body() ooo, @Req() request, @Res() response, @Header('test') header) {
            return {name: 'getTest', age: 12234}
        }
    
        @POST()
        public async postTest(request, response) {
            return {name: 'postTest'}
        }
    
        @DOWNLOAD()
        public async download(@Req() req) {
            return new DownloadFile('./testPPT.pptx')
        }
    
        @CONTROLLER(TestController1)
        public async testSubController() {
            console.log('Go to test controller 1')
        }
    
    }

    Usage

    createApp({
        id: 'api.test.app',
        name: 'api-test-app',
        modules: {
            test: {
                class: API,
                logger: true,
                signType: 'SHA1',
                port: 8080,
                controllers: [
                    `${path.resolve(__dirname, './controllers')}/**/*`
                ]
            }
        }
    }).then(app => {
        app.Logger.info('API is running')
    }).catch(e => {
        console.error(e)
    })

    @lakutata/core required.

    Documentations

    Module Options

    const moduleOptions:{
        port?: number
        controllers?: string | string[]
        ignoreTrailingSlash?: boolean
        maxParamLength?: number
        bodyLimit?: number
        onProtoPoisoning?: 'error' | 'remove' | 'ignore'
        onConstructorPoisoning?: 'error' | 'remove' | 'ignore'
        logger?: boolean | Logger
        connectionTimeout?: number
        keepAliveTimeout?: number
        multipart?: {
            addToBody?: boolean
            throwFileSizeLimit?: boolean
            limits?: {
                fieldNameSize?: number
                fieldSize?: number
                fields?: number
                fileSize?: number
                files?: number
                headerPairs?: number
            }
        },
        cors?: {
            origin?: boolean | string | string[] | RegExp
            methods?: string | string[]
            allowedHeaders?: string | string[]
            exposedHeaders?: string | string[]
            credentials?: boolean
            maxAge?: number
            preflightContinue?: boolean
            optionsSuccessStatus?: number
            preflight?: boolean
            strictPreflight?: boolean
            hideOptionsRoute?: boolean
        }
        signType?: 'MD5' | 'SHA1' | 'SHA3' | 'SHA224' | 'SHA256' | 'SHA384' | 'SHA512'
        responseFormatter?: (payload: TFormattedPayload, hasError: boolean) => { [prop: string]: any } | Promise<{ [prop: string]: any }>
    }

    How to Contribute

    Please let us know how can we help. Do check out issues for bug reports or suggestions first.

    License

    MIT

    Keywords

    Install

    npm i @lakutata-module/api

    DownloadsWeekly Downloads

    43

    Version

    1.0.29

    License

    MIT

    Unpacked Size

    458 kB

    Total Files

    276

    Last publish

    Collaborators

    • myq1991