Skip to content

Commit 99834eb

Browse files
authored
chore(docs): updated readme example and decorators
Simplified basic example and added parameters to the Class and Method decorators.
1 parent 4070098 commit 99834eb

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

README.md

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,7 @@ Your `tsconfig.json` needs the following flags:
3636

3737
```ts
3838
// pages/api/user.ts
39-
import {
40-
createHandler,
41-
Get,
42-
Post,
43-
HttpCode,
44-
Query,
45-
Body,
46-
NotFoundException
47-
} from '@storyofams/next-api-decorators';
39+
import { createHandler, Get, Post, Query, Body, NotFoundException } from '@storyofams/next-api-decorators';
4840

4941
class User {
5042
// GET /api/user
@@ -61,7 +53,6 @@ class User {
6153

6254
// POST /api/user
6355
@Post()
64-
@HttpCode(201)
6556
public createUser(@Body() body: any) {
6657
return User.create(body);
6758
}
@@ -106,20 +97,20 @@ export default createHandler(User);
10697

10798
### Class decorators
10899

109-
| | Description |
110-
| ----------- | -------------------------------------------------------------------------- |
111-
| `SetHeader` | Sets a header value into the response for all routes defined in the class. |
100+
| | Description |
101+
| ----------------------------------------- | -------------------------------------------------------------- |
102+
| `@SetHeader(name: string, value: string)` | Sets a header name/value into all routes defined in the class. |
112103

113104
### Method decorators
114105

115-
| | Description |
116-
| ----------- | --------------------------------------------------------- |
117-
| `Get` | Marks the method as `GET` handler. |
118-
| `Post` | Marks the method as `POST` handler. |
119-
| `Put` | Marks the method as `PUT` handler. |
120-
| `Delete` | Marks the method as `DELETE` handler. |
121-
| `SetHeader` | Sets a header name/value into the response for the route. |
122-
| `HttpCode` | Sets the http code the route response. |
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. |
123114

124115
### Parameter decorators
125116

0 commit comments

Comments
 (0)