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
console.log(`Add an image to product ${params.productId}`); // Path parameter is typed ✅
34
+
35
+
const reqBody =awaitrequest.json();
36
+
console.log(`Image description: ${reqBody.description}`); // Request body is typed ✅
37
+
38
+
returnHttpResponse.json(
39
+
{ id: 123, ...reqBody }, // Response body is also typed ✅
40
+
{ status: 201 },
34
41
);
35
42
}),
36
43
// ...
37
44
];
38
45
39
46
// 3. Subsequent usage is the same as the regular MSW usage.
40
-
import { setupWorker } from'msw'; // or `setupServer`
47
+
48
+
import { setupWorker } from'msw/browser';
49
+
// or
50
+
// import { setupServer } from 'msw/node';
41
51
42
52
awaitsetupWorker(...handlers).start();
43
53
```
44
54
45
-
### `createTypedRest(api, options?)`
55
+
### `createTypedHttp(api, options?)`
46
56
47
-
Creates a `typedRest` object based on the `api` function generated by aspida. This `typedRest` is a wrapper to write MSW's [request handler](https://v1.mswjs.io/docs/basics/request-handler).
57
+
Creates a `typedHttp` object based on the `api` function generated by aspida. This `typedHttp` is a wrapper to write MSW's [request handler](https://mswjs.io/docs/concepts/request-handler).
48
58
49
59
#### Options
50
60
51
61
-`baseURL` (optional): Specifies the base URL for the API. Works the same as aspida's `baseURL` option.
An object for writing MSW's [request handler](https://v1.mswjs.io/docs/basics/request-handler). Essentially, it is a thin wrapper for MSW's [`rest`](https://v1.mswjs.io/docs/api/rest). The usage is almost identical to [`rest`](https://v1.mswjs.io/docs/api/rest), but paths and methods are expressed in an aspida-like format.
69
+
An object for writing MSW's [request handler](https://mswjs.io/docs/concepts/request-handler). Essentially, it is a thin wrapper for MSW's [`http`](https://mswjs.io/docs/api/http). The usage is almost identical to `http`, but paths and methods are expressed in an aspida-like format.
Expressed as the `$`-prefixed HTTP method function, like `.$get(resolver)` or `.$post(resolver)`. The argument is MSW's [response resolver](https://v1.mswjs.io/docs/basics/response-resolver). The following three are typed from aspida's `api`, so no type annotations are required:
91
+
Expressed as the `$`-prefixed HTTP method function, like `.$get(resolver)` or `.$post(resolver)`. The argument is MSW's [response resolver](https://mswjs.io/docs/concepts/response-resolver). The following three are typed from aspida's `api`, so no type annotations are required:
0 commit comments