@zimic/interceptor 0.19.1-canary.2 → 0.19.1-canary.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-6PRFBMY7.mjs → chunk-7BR57OM2.mjs} +3 -3
- package/dist/chunk-7BR57OM2.mjs.map +1 -0
- package/dist/{chunk-3NJLJSD6.js → chunk-QB2A2272.js} +3 -3
- package/dist/chunk-QB2A2272.js.map +1 -0
- package/dist/cli.js +20 -20
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +4 -4
- package/dist/cli.mjs.map +1 -1
- package/dist/http.d.ts +268 -479
- package/dist/http.js +5 -5
- package/dist/http.js.map +1 -1
- package/dist/http.mjs +5 -5
- package/dist/http.mjs.map +1 -1
- package/dist/server.d.ts +14 -15
- package/dist/server.js +6 -6
- package/dist/server.mjs +1 -1
- package/package.json +3 -3
- package/src/cli/server/start.ts +1 -1
- package/src/cli/server/token/create.ts +1 -1
- package/src/http/interceptor/errors/NotRunningHttpInterceptorError.ts +3 -3
- package/src/http/interceptor/errors/RequestSavingSafeLimitExceededError.ts +2 -2
- package/src/http/interceptor/errors/RunningHttpInterceptorError.ts +3 -3
- package/src/http/interceptor/errors/UnknownHttpInterceptorPlatformError.ts +1 -1
- package/src/http/interceptor/factory.ts +1 -9
- package/src/http/interceptor/types/options.ts +32 -132
- package/src/http/interceptor/types/public.ts +160 -248
- package/src/http/interceptor/types/schema.ts +2 -3
- package/src/http/interceptorWorker/HttpInterceptorWorker.ts +1 -1
- package/src/http/interceptorWorker/errors/UnregisteredBrowserServiceWorkerError.ts +2 -2
- package/src/http/requestHandler/errors/DisabledRequestSavingError.ts +2 -2
- package/src/http/requestHandler/errors/TimesCheckError.ts +1 -1
- package/src/http/requestHandler/types/public.ts +60 -73
- package/src/http/requestHandler/types/restrictions.ts +6 -6
- package/src/server/errors/InvalidInterceptorTokenError.ts +1 -1
- package/src/server/errors/InvalidInterceptorTokenFileError.ts +1 -1
- package/src/server/errors/InvalidInterceptorTokenValueError.ts +1 -1
- package/src/server/errors/RunningInterceptorServerError.ts +1 -1
- package/src/server/factory.ts +3 -3
- package/src/server/types/options.ts +2 -3
- package/src/server/types/public.ts +8 -8
- package/dist/chunk-3NJLJSD6.js.map +0 -1
- package/dist/chunk-6PRFBMY7.mjs.map +0 -1
|
@@ -3,42 +3,11 @@ import { HttpSchema } from '@zimic/http';
|
|
|
3
3
|
import { SyncHttpInterceptorMethodHandler, AsyncHttpInterceptorMethodHandler } from './handlers';
|
|
4
4
|
import { HttpInterceptorPlatform, RemoteHttpInterceptorOptions, UnhandledRequestStrategy } from './options';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Configures if the intercepted requests are saved and how they are handled.
|
|
8
|
-
*
|
|
9
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
|
|
10
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/guides‐testing‐interceptor Testing}
|
|
11
|
-
*/
|
|
6
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor` API reference} */
|
|
12
7
|
export interface HttpInterceptorRequestSaving {
|
|
13
|
-
/**
|
|
14
|
-
* Whether {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler request handlers}
|
|
15
|
-
* should save their intercepted requests in memory and make them accessible through
|
|
16
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests`}.
|
|
17
|
-
*
|
|
18
|
-
* If you are using
|
|
19
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorchecktimes `interceptor.checkTimes()`}
|
|
20
|
-
* or
|
|
21
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerchecktimes `handler.checkTimes()`}
|
|
22
|
-
* during tests, consider enabling this option to get more detailed information in `TimesCheckError` errors.
|
|
23
|
-
*
|
|
24
|
-
* **Important**: If `requestSaving.enabled` is `true`, make sure to regularly clear the interceptor to avoid requests
|
|
25
|
-
* accumulating in memory. A common practice is to call
|
|
26
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorclear `interceptor.clear()`}
|
|
27
|
-
* after each test.
|
|
28
|
-
*
|
|
29
|
-
* @default process.env.NODE_ENV === 'test'
|
|
30
|
-
*/
|
|
8
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor` API reference} */
|
|
31
9
|
enabled: boolean;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The safe number of requests to save in memory before logging warnings in the console. If `requestSaving.enabled` is
|
|
35
|
-
* `true` and the interceptor is not regularly cleared with
|
|
36
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorclear `interceptor.clear()`},
|
|
37
|
-
* the requests may accumulate in memory and cause performance issues. This option does not limit the number of
|
|
38
|
-
* requests saved in memory, only when to log warnings.
|
|
39
|
-
*
|
|
40
|
-
* @default 1000
|
|
41
|
-
*/
|
|
10
|
+
/** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor` API reference} */
|
|
42
11
|
safeLimit: number;
|
|
43
12
|
}
|
|
44
13
|
|
|
@@ -46,7 +15,7 @@ export interface HttpInterceptorRequestSaving {
|
|
|
46
15
|
* An interceptor to handle HTTP requests and return mock responses. The methods, paths, status codes, parameters, and
|
|
47
16
|
* responses are statically-typed based on the provided service schema.
|
|
48
17
|
*
|
|
49
|
-
* @see {@link https://
|
|
18
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor` API reference}
|
|
50
19
|
*/
|
|
51
20
|
// The schema is still a generic type for backward compatibility.
|
|
52
21
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
@@ -54,23 +23,32 @@ export interface HttpInterceptor<_Schema extends HttpSchema> {
|
|
|
54
23
|
/**
|
|
55
24
|
* The base URL used by the interceptor.
|
|
56
25
|
*
|
|
57
|
-
* @see {@link https://
|
|
26
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorbaseurl `interceptor.baseURL` API reference}
|
|
58
27
|
*/
|
|
59
28
|
baseURL: string;
|
|
60
29
|
|
|
61
30
|
/**
|
|
62
31
|
* Configures if the intercepted requests are saved and how they are handled.
|
|
63
32
|
*
|
|
64
|
-
* @see {@link https://
|
|
65
|
-
* @see {@link https://
|
|
33
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor` API reference}
|
|
34
|
+
* @see {@link https://zimic.dev/docs/interceptor/guides/http/testing Testing}
|
|
66
35
|
*/
|
|
67
36
|
requestSaving: HttpInterceptorRequestSaving;
|
|
68
37
|
|
|
38
|
+
/**
|
|
39
|
+
* The strategy to use for unhandled requests. If a request starts with the base URL of the interceptor, but no
|
|
40
|
+
* matching handler exists, this strategy will be used. If a function is provided, it will be called with the
|
|
41
|
+
* unhandled request.
|
|
42
|
+
*
|
|
43
|
+
* @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests}
|
|
44
|
+
*/
|
|
45
|
+
onUnhandledRequest?: UnhandledRequestStrategy;
|
|
46
|
+
|
|
69
47
|
/**
|
|
70
48
|
* The platform the interceptor is running on.
|
|
71
49
|
*
|
|
72
50
|
* @readonly
|
|
73
|
-
* @see {@link https://
|
|
51
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorplatform `interceptor.platform` API reference}
|
|
74
52
|
*/
|
|
75
53
|
get platform(): HttpInterceptorPlatform | null;
|
|
76
54
|
|
|
@@ -78,7 +56,7 @@ export interface HttpInterceptor<_Schema extends HttpSchema> {
|
|
|
78
56
|
* Whether the interceptor is currently running and ready to use.
|
|
79
57
|
*
|
|
80
58
|
* @readonly
|
|
81
|
-
* @see {@link https://
|
|
59
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorisrunning `interceptor.isRunning` API reference}
|
|
82
60
|
*/
|
|
83
61
|
get isRunning(): boolean;
|
|
84
62
|
|
|
@@ -90,55 +68,53 @@ export interface HttpInterceptor<_Schema extends HttpSchema> {
|
|
|
90
68
|
*
|
|
91
69
|
* @throws {UnregisteredServiceWorkerError} When the worker is targeting a browser environment and the mock service
|
|
92
70
|
* worker is not registered.
|
|
93
|
-
* @see {@link https://
|
|
71
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstart `interceptor.start()` API reference}
|
|
94
72
|
*/
|
|
95
73
|
start: () => Promise<void>;
|
|
96
74
|
|
|
97
75
|
/**
|
|
98
76
|
* Stops the interceptor, preventing it from intercepting HTTP requests. Stopped interceptors are automatically
|
|
99
77
|
* cleared, exactly as if
|
|
100
|
-
* {@link https://
|
|
101
|
-
*
|
|
78
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorclear `interceptor.clear()`} had been
|
|
79
|
+
* called.
|
|
102
80
|
*
|
|
103
|
-
* @see {@link https://
|
|
81
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstop `interceptor.stop()` API reference}
|
|
104
82
|
*/
|
|
105
83
|
stop: () => Promise<void>;
|
|
106
84
|
|
|
107
85
|
/**
|
|
108
86
|
* Checks if all handlers created by this interceptor have matched the number of requests declared with
|
|
109
|
-
* {@link https://
|
|
87
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()`}.
|
|
110
88
|
*
|
|
111
89
|
* If some handler has matched fewer or more requests than expected, this method will throw a `TimesCheckError` error,
|
|
112
90
|
* including a stack trace to the
|
|
113
|
-
* {@link https://
|
|
114
|
-
*
|
|
91
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()`} that was not
|
|
92
|
+
* satisfied.
|
|
115
93
|
*
|
|
116
94
|
* This is useful in an `afterEach` hook (or equivalent) to make sure that all expected requests were made at the end
|
|
117
95
|
* of each test.
|
|
118
96
|
*
|
|
119
|
-
* When
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* expected and received data. This is useful for debugging requests that did not match a handler with
|
|
124
|
-
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction restrictions}.
|
|
97
|
+
* When {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `requestSaving.enabled`} is `true` in
|
|
98
|
+
* your interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the expected and
|
|
99
|
+
* received data. This is useful for debugging requests that did not match a handler with
|
|
100
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}.
|
|
125
101
|
*
|
|
126
102
|
* @throws {TimesCheckError} If some handler has matched less or more requests than the expected number of requests.
|
|
127
|
-
* @see {@link https://
|
|
128
|
-
* @see {@link https://
|
|
103
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorchecktimes `interceptor.checkTimes()` API reference}
|
|
104
|
+
* @see {@link https://zimic.dev/docs/interceptor/guides/http/testing Testing guide}
|
|
129
105
|
*/
|
|
130
106
|
checkTimes: (() => void) | (() => Promise<void>);
|
|
131
107
|
|
|
132
108
|
/**
|
|
133
109
|
* Clears the interceptor and all of its
|
|
134
|
-
* {@link https://
|
|
135
|
-
*
|
|
136
|
-
*
|
|
110
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} instances, including their
|
|
111
|
+
* registered responses and intercepted requests. After calling this method, the interceptor will no longer intercept
|
|
112
|
+
* any requests until new mock responses are registered.
|
|
137
113
|
*
|
|
138
114
|
* This method is useful to reset the interceptor mocks between tests.
|
|
139
115
|
*
|
|
140
116
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
141
|
-
* @see {@link https://
|
|
117
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorclear `interceptor.clear()` API reference}
|
|
142
118
|
*/
|
|
143
119
|
clear: (() => void) | (() => Promise<void>);
|
|
144
120
|
}
|
|
@@ -148,34 +124,25 @@ export interface HttpInterceptor<_Schema extends HttpSchema> {
|
|
|
148
124
|
* and responses are statically-typed based on the provided service schema.
|
|
149
125
|
*
|
|
150
126
|
* To intercept HTTP requests, the interceptor must have been started with
|
|
151
|
-
* {@link https://
|
|
127
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstart `interceptor.start()`}.
|
|
152
128
|
*
|
|
153
|
-
* @see {@link https://
|
|
129
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor` API reference}
|
|
154
130
|
*/
|
|
155
131
|
export interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpInterceptor<Schema> {
|
|
156
132
|
/** @readonly */
|
|
157
133
|
get type(): 'local';
|
|
158
134
|
|
|
159
|
-
/**
|
|
160
|
-
* The strategy to use for unhandled requests. If a request starts with the base URL of the interceptor, but no
|
|
161
|
-
* matching handler exists, this strategy will be used. If a function is provided, it will be called with the
|
|
162
|
-
* unhandled request.
|
|
163
|
-
*
|
|
164
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
165
|
-
*/
|
|
166
135
|
onUnhandledRequest?: UnhandledRequestStrategy.Local;
|
|
167
136
|
|
|
168
137
|
/**
|
|
169
|
-
* Creates a GET
|
|
170
|
-
*
|
|
171
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
138
|
+
* Creates a GET {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
139
|
+
* The path and method must be declared in the interceptor schema.
|
|
172
140
|
*
|
|
173
141
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
174
142
|
* interceptor, and the method, path,
|
|
175
|
-
* {@link https://
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
143
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
144
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
145
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
179
146
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
180
147
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
181
148
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -183,25 +150,22 @@ export interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpInt
|
|
|
183
150
|
*
|
|
184
151
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
185
152
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
186
|
-
* @returns A GET
|
|
187
|
-
*
|
|
188
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
153
|
+
* @returns A GET {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
154
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
189
155
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
190
|
-
* @see {@link https://
|
|
156
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
191
157
|
*/
|
|
192
158
|
get: SyncHttpInterceptorMethodHandler<Schema, 'GET'>;
|
|
193
159
|
|
|
194
160
|
/**
|
|
195
|
-
* Creates a POST
|
|
196
|
-
*
|
|
197
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
161
|
+
* Creates a POST {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
162
|
+
* The path and method must be declared in the interceptor schema.
|
|
198
163
|
*
|
|
199
164
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
200
165
|
* interceptor, and the method, path,
|
|
201
|
-
* {@link https://
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
166
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
167
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
168
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
205
169
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
206
170
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
207
171
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -209,25 +173,22 @@ export interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpInt
|
|
|
209
173
|
*
|
|
210
174
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
211
175
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
212
|
-
* @returns A POST
|
|
213
|
-
*
|
|
214
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
176
|
+
* @returns A POST {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
177
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
215
178
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
216
|
-
* @see {@link https://
|
|
179
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
217
180
|
*/
|
|
218
181
|
post: SyncHttpInterceptorMethodHandler<Schema, 'POST'>;
|
|
219
182
|
|
|
220
183
|
/**
|
|
221
|
-
* Creates a PATCH
|
|
222
|
-
*
|
|
223
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
184
|
+
* Creates a PATCH {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
185
|
+
* The path and method must be declared in the interceptor schema.
|
|
224
186
|
*
|
|
225
187
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
226
188
|
* interceptor, and the method, path,
|
|
227
|
-
* {@link https://
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
189
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
190
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
191
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
231
192
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
232
193
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
233
194
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -235,25 +196,22 @@ export interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpInt
|
|
|
235
196
|
*
|
|
236
197
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
237
198
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
238
|
-
* @returns A PATCH
|
|
239
|
-
*
|
|
240
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
199
|
+
* @returns A PATCH {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
200
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
241
201
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
242
|
-
* @see {@link https://
|
|
202
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
243
203
|
*/
|
|
244
204
|
patch: SyncHttpInterceptorMethodHandler<Schema, 'PATCH'>;
|
|
245
205
|
|
|
246
206
|
/**
|
|
247
|
-
* Creates a PUT
|
|
248
|
-
*
|
|
249
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
207
|
+
* Creates a PUT {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
208
|
+
* The path and method must be declared in the interceptor schema.
|
|
250
209
|
*
|
|
251
210
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
252
211
|
* interceptor, and the method, path,
|
|
253
|
-
* {@link https://
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
212
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
213
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
214
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
257
215
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
258
216
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
259
217
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -261,25 +219,22 @@ export interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpInt
|
|
|
261
219
|
*
|
|
262
220
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
263
221
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
264
|
-
* @returns A PUT
|
|
265
|
-
*
|
|
266
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
222
|
+
* @returns A PUT {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
223
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
267
224
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
268
|
-
* @see {@link https://
|
|
225
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
269
226
|
*/
|
|
270
227
|
put: SyncHttpInterceptorMethodHandler<Schema, 'PUT'>;
|
|
271
228
|
|
|
272
229
|
/**
|
|
273
|
-
* Creates a DELETE
|
|
274
|
-
*
|
|
275
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
230
|
+
* Creates a DELETE {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a
|
|
231
|
+
* path. The path and method must be declared in the interceptor schema.
|
|
276
232
|
*
|
|
277
233
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
278
234
|
* interceptor, and the method, path,
|
|
279
|
-
* {@link https://
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
235
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
236
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
237
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
283
238
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
284
239
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
285
240
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -287,25 +242,22 @@ export interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpInt
|
|
|
287
242
|
*
|
|
288
243
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
289
244
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
290
|
-
* @returns A DELETE
|
|
291
|
-
*
|
|
292
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
245
|
+
* @returns A DELETE {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
246
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
293
247
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
294
|
-
* @see {@link https://
|
|
248
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
295
249
|
*/
|
|
296
250
|
delete: SyncHttpInterceptorMethodHandler<Schema, 'DELETE'>;
|
|
297
251
|
|
|
298
252
|
/**
|
|
299
|
-
* Creates a HEAD
|
|
300
|
-
*
|
|
301
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
253
|
+
* Creates a HEAD {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
254
|
+
* The path and method must be declared in the interceptor schema.
|
|
302
255
|
*
|
|
303
256
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
304
257
|
* interceptor, and the method, path,
|
|
305
|
-
* {@link https://
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
258
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
259
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
260
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
309
261
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
310
262
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
311
263
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -313,25 +265,22 @@ export interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpInt
|
|
|
313
265
|
*
|
|
314
266
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
315
267
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
316
|
-
* @returns A HEAD
|
|
317
|
-
*
|
|
318
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
268
|
+
* @returns A HEAD {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
269
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
319
270
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
320
|
-
* @see {@link https://
|
|
271
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
321
272
|
*/
|
|
322
273
|
head: SyncHttpInterceptorMethodHandler<Schema, 'HEAD'>;
|
|
323
274
|
|
|
324
275
|
/**
|
|
325
|
-
* Creates an OPTIONS
|
|
326
|
-
*
|
|
327
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
276
|
+
* Creates an OPTIONS {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a
|
|
277
|
+
* path. The path and method must be declared in the interceptor schema.
|
|
328
278
|
*
|
|
329
279
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
330
280
|
* interceptor, and the method, path,
|
|
331
|
-
* {@link https://
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
281
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
282
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
283
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
335
284
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
336
285
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
337
286
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -339,11 +288,10 @@ export interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpInt
|
|
|
339
288
|
*
|
|
340
289
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
341
290
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
342
|
-
* @returns An OPTIONS
|
|
343
|
-
*
|
|
344
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
291
|
+
* @returns An OPTIONS {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
292
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
345
293
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
346
|
-
* @see {@link https://
|
|
294
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
347
295
|
*/
|
|
348
296
|
options: SyncHttpInterceptorMethodHandler<Schema, 'OPTIONS'>;
|
|
349
297
|
|
|
@@ -357,11 +305,10 @@ export interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpInt
|
|
|
357
305
|
* and responses are statically-typed based on the provided service schema.
|
|
358
306
|
*
|
|
359
307
|
* To intercept HTTP requests, the interceptor must have been started with
|
|
360
|
-
* {@link https://
|
|
361
|
-
*
|
|
362
|
-
* running.
|
|
308
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstart `interceptor.start()`} and an
|
|
309
|
+
* {@link https://zimic.dev/docs/interceptor/cli/server interceptor server} should be running.
|
|
363
310
|
*
|
|
364
|
-
* @see {@link https://
|
|
311
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor` API reference}
|
|
365
312
|
*/
|
|
366
313
|
export interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpInterceptor<Schema> {
|
|
367
314
|
/** @readonly */
|
|
@@ -371,35 +318,25 @@ export interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIn
|
|
|
371
318
|
* Options to authenticate the interceptor when connecting to an interceptor server. This is required if the
|
|
372
319
|
* interceptor server was started with the `--tokens-dir` option.
|
|
373
320
|
*
|
|
374
|
-
* @see {@link https://
|
|
321
|
+
* @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors#interceptor-server-authentication Interceptor server authentication}
|
|
375
322
|
*/
|
|
376
323
|
auth?: RemoteHttpInterceptorOptions['auth'];
|
|
377
324
|
|
|
378
|
-
/**
|
|
379
|
-
* The strategy to use for unhandled requests. If a request starts with the base URL of the interceptor, but no
|
|
380
|
-
* matching handler exists, this strategy will be used. If a function is provided, it will be called with the
|
|
381
|
-
* unhandled request.
|
|
382
|
-
*
|
|
383
|
-
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
384
|
-
*/
|
|
385
325
|
onUnhandledRequest?: UnhandledRequestStrategy.Remote;
|
|
386
326
|
|
|
387
327
|
/**
|
|
388
|
-
* Creates a GET
|
|
389
|
-
*
|
|
390
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
328
|
+
* Creates a GET {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
329
|
+
* The path and method must be declared in the interceptor schema.
|
|
391
330
|
*
|
|
392
|
-
* When using a
|
|
393
|
-
* {@link https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors remote interceptor}, creating
|
|
331
|
+
* When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
|
|
394
332
|
* a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
|
|
395
333
|
* apply them by awaiting the handler.
|
|
396
334
|
*
|
|
397
335
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
398
336
|
* interceptor, and the method, path,
|
|
399
|
-
* {@link https://
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
337
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
338
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
339
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
403
340
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
404
341
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
405
342
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -407,30 +344,26 @@ export interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIn
|
|
|
407
344
|
*
|
|
408
345
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
409
346
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
410
|
-
* @returns A GET
|
|
411
|
-
*
|
|
412
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
347
|
+
* @returns A GET {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
348
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
413
349
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
414
|
-
* @see {@link https://
|
|
350
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
415
351
|
*/
|
|
416
352
|
get: AsyncHttpInterceptorMethodHandler<Schema, 'GET'>;
|
|
417
353
|
|
|
418
354
|
/**
|
|
419
|
-
* Creates a POST
|
|
420
|
-
*
|
|
421
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
355
|
+
* Creates a POST {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
356
|
+
* The path and method must be declared in the interceptor schema.
|
|
422
357
|
*
|
|
423
|
-
* When using a
|
|
424
|
-
* {@link https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors remote interceptor}, creating
|
|
358
|
+
* When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
|
|
425
359
|
* a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
|
|
426
360
|
* apply them by awaiting the handler.
|
|
427
361
|
*
|
|
428
362
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
429
363
|
* interceptor, and the method, path,
|
|
430
|
-
* {@link https://
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
364
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
365
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
366
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
434
367
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
435
368
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
436
369
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -438,30 +371,26 @@ export interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIn
|
|
|
438
371
|
*
|
|
439
372
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
440
373
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
441
|
-
* @returns A POST
|
|
442
|
-
*
|
|
443
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
374
|
+
* @returns A POST {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
375
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
444
376
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
445
|
-
* @see {@link https://
|
|
377
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
446
378
|
*/
|
|
447
379
|
post: AsyncHttpInterceptorMethodHandler<Schema, 'POST'>;
|
|
448
380
|
|
|
449
381
|
/**
|
|
450
|
-
* Creates a PATCH
|
|
451
|
-
*
|
|
452
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
382
|
+
* Creates a PATCH {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
383
|
+
* The path and method must be declared in the interceptor schema.
|
|
453
384
|
*
|
|
454
|
-
* When using a
|
|
455
|
-
* {@link https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors remote interceptor}, creating
|
|
385
|
+
* When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
|
|
456
386
|
* a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
|
|
457
387
|
* apply them by awaiting the handler.
|
|
458
388
|
*
|
|
459
389
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
460
390
|
* interceptor, and the method, path,
|
|
461
|
-
* {@link https://
|
|
462
|
-
*
|
|
463
|
-
*
|
|
464
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
391
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
392
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
393
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
465
394
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
466
395
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
467
396
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -469,30 +398,26 @@ export interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIn
|
|
|
469
398
|
*
|
|
470
399
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
471
400
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
472
|
-
* @returns A PATCH
|
|
473
|
-
*
|
|
474
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
401
|
+
* @returns A PATCH {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
402
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
475
403
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
476
|
-
* @see {@link https://
|
|
404
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
477
405
|
*/
|
|
478
406
|
patch: AsyncHttpInterceptorMethodHandler<Schema, 'PATCH'>;
|
|
479
407
|
|
|
480
408
|
/**
|
|
481
|
-
* Creates a PUT
|
|
482
|
-
*
|
|
483
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
409
|
+
* Creates a PUT {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
410
|
+
* The path and method must be declared in the interceptor schema.
|
|
484
411
|
*
|
|
485
|
-
* When using a
|
|
486
|
-
* {@link https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors remote interceptor}, creating
|
|
412
|
+
* When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
|
|
487
413
|
* a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
|
|
488
414
|
* apply them by awaiting the handler.
|
|
489
415
|
*
|
|
490
416
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
491
417
|
* interceptor, and the method, path,
|
|
492
|
-
* {@link https://
|
|
493
|
-
*
|
|
494
|
-
*
|
|
495
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
418
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
419
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
420
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
496
421
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
497
422
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
498
423
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -500,30 +425,26 @@ export interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIn
|
|
|
500
425
|
*
|
|
501
426
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
502
427
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
503
|
-
* @returns A PUT
|
|
504
|
-
*
|
|
505
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
428
|
+
* @returns A PUT {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
429
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
506
430
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
507
|
-
* @see {@link https://
|
|
431
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
508
432
|
*/
|
|
509
433
|
put: AsyncHttpInterceptorMethodHandler<Schema, 'PUT'>;
|
|
510
434
|
|
|
511
435
|
/**
|
|
512
|
-
* Creates a DELETE
|
|
513
|
-
*
|
|
514
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
436
|
+
* Creates a DELETE {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a
|
|
437
|
+
* path. The path and method must be declared in the interceptor schema.
|
|
515
438
|
*
|
|
516
|
-
* When using a
|
|
517
|
-
* {@link https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors remote interceptor}, creating
|
|
439
|
+
* When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
|
|
518
440
|
* a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
|
|
519
441
|
* apply them by awaiting the handler.
|
|
520
442
|
*
|
|
521
443
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
522
444
|
* interceptor, and the method, path,
|
|
523
|
-
* {@link https://
|
|
524
|
-
*
|
|
525
|
-
*
|
|
526
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
445
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
446
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
447
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
527
448
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
528
449
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
529
450
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -531,30 +452,26 @@ export interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIn
|
|
|
531
452
|
*
|
|
532
453
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
533
454
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
534
|
-
* @returns A DELETE
|
|
535
|
-
*
|
|
536
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
455
|
+
* @returns A DELETE {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
456
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
537
457
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
538
|
-
* @see {@link https://
|
|
458
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
539
459
|
*/
|
|
540
460
|
delete: AsyncHttpInterceptorMethodHandler<Schema, 'DELETE'>;
|
|
541
461
|
|
|
542
462
|
/**
|
|
543
|
-
* Creates a HEAD
|
|
544
|
-
*
|
|
545
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
463
|
+
* Creates a HEAD {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
|
|
464
|
+
* The path and method must be declared in the interceptor schema.
|
|
546
465
|
*
|
|
547
|
-
* When using a
|
|
548
|
-
* {@link https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors remote interceptor}, creating
|
|
466
|
+
* When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
|
|
549
467
|
* a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
|
|
550
468
|
* apply them by awaiting the handler.
|
|
551
469
|
*
|
|
552
470
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
553
471
|
* interceptor, and the method, path,
|
|
554
|
-
* {@link https://
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
472
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
473
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
474
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
558
475
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
559
476
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
560
477
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -562,30 +479,26 @@ export interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIn
|
|
|
562
479
|
*
|
|
563
480
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
564
481
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
565
|
-
* @returns A HEAD
|
|
566
|
-
*
|
|
567
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
482
|
+
* @returns A HEAD {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
483
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
568
484
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
569
|
-
* @see {@link https://
|
|
485
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
570
486
|
*/
|
|
571
487
|
head: AsyncHttpInterceptorMethodHandler<Schema, 'HEAD'>;
|
|
572
488
|
|
|
573
489
|
/**
|
|
574
|
-
* Creates an OPTIONS
|
|
575
|
-
*
|
|
576
|
-
* a path. The path and method must be declared in the interceptor schema.
|
|
490
|
+
* Creates an OPTIONS {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a
|
|
491
|
+
* path. The path and method must be declared in the interceptor schema.
|
|
577
492
|
*
|
|
578
|
-
* When using a
|
|
579
|
-
* {@link https://github.com/zimicjs/zimic/wiki/getting‐started#remote-http-interceptors remote interceptor}, creating
|
|
493
|
+
* When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
|
|
580
494
|
* a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
|
|
581
495
|
* apply them by awaiting the handler.
|
|
582
496
|
*
|
|
583
497
|
* After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
|
|
584
498
|
* interceptor, and the method, path,
|
|
585
|
-
* {@link https://
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
* of the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
499
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
|
|
500
|
+
* {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
|
|
501
|
+
* the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
|
|
589
502
|
* preference over older ones. This allows you to declare generic and specific handlers based on their order of
|
|
590
503
|
* creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
|
|
591
504
|
* test case can return a list with some users. In this case, the specific handler will be considered first as long as
|
|
@@ -593,11 +506,10 @@ export interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIn
|
|
|
593
506
|
*
|
|
594
507
|
* @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
|
|
595
508
|
* to specify the original path as a type parameter to get type-inference and type-validation.
|
|
596
|
-
* @returns An OPTIONS
|
|
597
|
-
*
|
|
598
|
-
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
509
|
+
* @returns An OPTIONS {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
|
|
510
|
+
* provided path. The path and method must be declared in the interceptor schema.
|
|
599
511
|
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
600
|
-
* @see {@link https://
|
|
512
|
+
* @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
|
|
601
513
|
*/
|
|
602
514
|
options: AsyncHttpInterceptorMethodHandler<Schema, 'OPTIONS'>;
|
|
603
515
|
|