1- <p align =" center " >
1+ <div align =" center " >
22 <a aria-label =" Story of AMS logo " href =" https://storyofams.com/ " target =" _blank " align =" center " >
33 <img src="https://storyofams.com/public/[email protected] " alt="Story of AMS" width="120"> 44 </a >
55 <h1 align =" center " >@storyofams/next-api-decorators</h1 >
6- </p >
7-
8- <p align =" center " >Collection of decorators to create typed Next.js API routes, with easy request validation and transformation.</p >
6+ <p align =" center " >
7+ <a aria-label="releases" href="https://GitHub.com/storyofams/next-api-decorators/releases/" target="_blank">
8+ <img src="https://github.com/storyofams/next-api-decorators/workflows/Release/badge.svg">
9+ </a>
10+ <a aria-label="npm" href="https://www.npmjs.com/package/@storyofams/next-api-decorators" target="_blank">
11+ <img src="https://img.shields.io/npm/v/@storyofams/next-api-decorators">
12+ </a>
13+ <a aria-label="codecov" href="https://codecov.io/gh/storyofams/nextjs-api-decorators" target="_blank">
14+ <img src="https://codecov.io/gh/storyofams/next-api-decorators/branch/master/graph/badge.svg?token=ZV0YT4HU5H">
15+ </a>
16+ <a aria-label="stars" href="https://github.com/storyofams/next-api-decorators/stargazers/" target="_blank">
17+ <img src="https://img.shields.io/github/stars/storyofams/next-api-decorators.svg?style=social&label=Star&maxAge=86400" />
18+ </a>
19+ </p >
20+ </div >
921
1022---
1123
24+ Collection of decorators to create typed Next.js API routes, with easy request validation and transformation.
25+
1226## Installation
1327
1428Add the package to your project:
@@ -23,11 +37,17 @@ Since decorators are still in proposal state, you need to add the following plug
2337$ yarn add -D babel-plugin-transform-typescript-metadata @babel/plugin-proposal-decorators babel-plugin-parameter-decorator
2438```
2539
40+ Make sure to add the following lines to the ` plugins ` section in your babel configuration file:
41+ ``` json
42+ " babel-plugin-transform-typescript-metadata" ,
43+ [" @babel/plugin-proposal-decorators" , { "legacy" : true }],
44+ " babel-plugin-parameter-decorator" ,
45+ ```
46+
2647Your ` tsconfig.json ` needs the following flags:
2748
2849``` json
29- "experimentalDecorators" : true ,
30- "emitDecoratorMetadata" : true
50+ "experimentalDecorators" : true
3151```
3252
3353## Usage
@@ -103,14 +123,14 @@ export default createHandler(User);
103123
104124### Method decorators
105125
106- | | Description |
107- | ----------------------------------------- | -------------------------------------------------- |
108- | ` @Get() ` | Marks the method as ` GET ` handler. |
109- | ` @Post() ` | Marks the method as ` POST ` handler. |
110- | ` @Put() ` | Marks the method as ` PUT ` handler. |
111- | ` @Delete() ` | Marks the method as ` DELETE ` handler. |
112- | ` @SetHeader(name: string, value: string) ` | Sets a header name/value into the route response. |
113- | ` @HttpCode(code: number) ` | Sets the http code in the route response. |
126+ | | Description |
127+ | ----------------------------------------- | ------------------------------------------------- |
128+ | ` @Get() ` | Marks the method as ` GET ` handler. |
129+ | ` @Post() ` | Marks the method as ` POST ` handler. |
130+ | ` @Put() ` | Marks the method as ` PUT ` handler. |
131+ | ` @Delete() ` | Marks the method as ` DELETE ` handler. |
132+ | ` @SetHeader(name: string, value: string) ` | Sets a header name/value into the route response. |
133+ | ` @HttpCode(code: number) ` | Sets the http code in the route response. |
114134
115135### Parameter decorators
116136
@@ -133,8 +153,8 @@ Pipes are being used to validate and transform incoming values. The pipes can be
133153
134154⚠️ Beware that they throw when the value is invalid.
135155
136- | | Description | Remarks |
137- | ------------------ | -------------------------------------------- | --------------------------------------------- |
156+ | | Description | Remarks |
157+ | ------------------ | ------------------------------------------- | --------------------------------------------- |
138158| ` ParseNumberPipe ` | Validates and transforms ` Number ` strings. | Uses ` parseFloat ` under the hood |
139159| ` ParseBooleanPipe ` | Validates and transforms ` Boolean ` strings. | Allows ` 'true' ` and ` 'false' ` as valid values |
140160
0 commit comments