npm package: @lakutata-module/api
Description: Lakutata API Module
Author: alex.ma
Latest version: 1.0.29

<div style="text-align:center">
	<img src="https://gitee.com/nnxr/lakutata-module-api/raw/master/assets/lakutata-banner.png" />
</div>

[![NPM Version](https://img.shields.io/npm/v/@lakutata-module/api?color=informational&style=flat-square)](https://npmjs.org/package/@lakutata-module/api)
[![NODE Version](https://img.shields.io/node/v/@lakutata-module/api?color=informational&style=flat-square)](https://npmjs.org/package/@lakutata-module/api)
[![Known Vulnerabilities](https://snyk.io/test/npm/@lakutata-module/api/badge.svg?style=flat-square)](https://snyk.io/test/npm/@lakutata-module/api)
[![NPM Download](https://img.shields.io/npm/dm/@lakutata-module/api?style=flat-square)](https://npmjs.org/package/@lakutata-module/api)

## Quickstart

#### Controller Example

```typescript
@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

```typescript
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

```typescript
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](https://gitee.com/nnxr/lakutata-module-api/issues) for bug reports or suggestions first.

## License

[MIT](LICENSE)