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
feat: add response validation functionality to express, next and nest (#121)
* feat: run `zod` validation on response interceptor
* refactor: get app router from request context and throw server error
* feat: make response parsing opt-in
* feat: infer proper types for `initNestServer`
* cleanup some code and add tests
* feat: response validation for express and next
* docs: add docs for response validation
* chore: changeset
* fix: failing tests
* refactor: use @TsRest for everything, deprecate @Api
* fix: unused import
---------
Co-authored-by: Youssef Gaber <1728215+Gabrola@users.noreply.github.com>
async getPost(@TsRestRequest() { params: { id } }:RequestShapes['getPost']) {
23
23
const post =awaitthis.postService.getPost(id);
24
24
@@ -37,38 +37,56 @@ To implement a nested contract, you can simply call `nestControllerContract(cont
37
37
38
38
Having the controller class implement `NestControllerInterface` ensures that your controller implements all the routes defined in the contract. In addition, it ensures the type safety of the responses returned.
39
39
40
-
The `@Api` decorator takes the route, defines the path and method for the controller route.
40
+
The `@TsRest` decorator takes the route, defines the path and method for the controller route and also configures ts-rest options.
41
41
42
42
The `@TsRestRequest` decorator takes the contract route defined in the `@Api` decorator, and returns the parsed and validated (if using Zod) request params, query and body.
43
43
44
44
As Typescript cannot infer class method parameter types from an implemented interface, we need to explicitly define the type for the request parameter using the `NestRequestShapes` type.
45
45
46
-
## JSON Query Parameters
46
+
## Configuration
47
+
48
+
To configure certain ts-rest options you can use the `@TsRest` decorator on either your Controller or use the existing `@Api` decorator.
49
+
50
+
### JSON Query Parameters
47
51
48
-
To handle JSON query parameters, you can use the `@JsonQuery()` decorator on either your Controller classes or individual endpoint methods.
52
+
To handle JSON query parameters, pass the `jsonQuery` option to the `@TsRest` decorator on your entire controller.
0 commit comments