You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+58Lines changed: 58 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -99,3 +99,61 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
99
99
## License
100
100
101
101
Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE).
102
+
103
+
## API Conventions
104
+
105
+
### Response Envelope
106
+
107
+
Endpoints using the custom `@Api({ envelope: true })` decorator option return:
108
+
109
+
```
110
+
{ "success": true, "data": <payload> }
111
+
```
112
+
113
+
Errors are normalized by the global `HttpExceptionFilter` into:
114
+
115
+
```
116
+
{
117
+
"success": false,
118
+
"error": {
119
+
"statusCode": 400,
120
+
"message": "Validation failed",
121
+
"details": {},
122
+
"path": "/endpoint",
123
+
"timestamp": "2025-01-01T00:00:00.000Z"
124
+
}
125
+
}
126
+
```
127
+
128
+
### Pagination Shape
129
+
130
+
Paginated endpoints (with `paginatedResponseType`) return (inside the envelope when enabled):
131
+
132
+
```
133
+
{
134
+
"items": [ ... ],
135
+
"pageInfo": {
136
+
"hasNextPage": true,
137
+
"hasPreviousPage": false,
138
+
"startCursor": "0",
139
+
"endCursor": "25"
140
+
},
141
+
"totalCount": 1234,
142
+
"meta": { "company": { ... } }
143
+
}
144
+
```
145
+
146
+
Use `buildPaginatedResult({ items, skip, take, totalCount, meta })` in services.
147
+
148
+
### Automatic Swagger Params
149
+
150
+
Annotate DTO properties with `@Field({ inQuery: true })` or `@Field({ inPath: true })`. Add those DTOs to `queriesFrom` / `pathParamsFrom` in `@Api()` and Swagger params are generated automatically.
Throw standard Nest `HttpException` subclasses. The filter wraps them in the envelope. Custom non-Http errors can be mapped by extending the filter if needed.
0 commit comments