2021-01-07 11:46:05 -08:00
|
|
|
# class: Route
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-07 11:46:05 -08:00
|
|
|
|
2021-01-14 07:48:56 -08:00
|
|
|
Whenever a network route is set up with [`method: Page.route`] or [`method: BrowserContext.route`], the `Route` object
|
|
|
|
allows to handle the route.
|
2021-01-07 11:46:05 -08:00
|
|
|
|
2022-05-11 16:07:00 +01:00
|
|
|
Learn more about [networking](../network.md).
|
|
|
|
|
2021-01-07 11:46:05 -08:00
|
|
|
## async method: Route.abort
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-07 11:46:05 -08:00
|
|
|
|
|
|
|
Aborts the route's request.
|
|
|
|
|
|
|
|
### param: Route.abort.errorCode
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2022-04-06 19:02:10 -07:00
|
|
|
- `errorCode` ?<[string]>
|
2021-01-07 11:46:05 -08:00
|
|
|
|
|
|
|
Optional error code. Defaults to `failed`, could be one of the following:
|
2021-01-14 07:48:56 -08:00
|
|
|
* `'aborted'` - An operation was aborted (due to user action)
|
|
|
|
* `'accessdenied'` - Permission to access a resource, other than the network, was denied
|
|
|
|
* `'addressunreachable'` - The IP address is unreachable. This usually means that there is no route to the specified
|
|
|
|
host or network.
|
|
|
|
* `'blockedbyclient'` - The client chose to block the request.
|
|
|
|
* `'blockedbyresponse'` - The request failed because the response was delivered along with requirements which are not
|
|
|
|
met ('X-Frame-Options' and 'Content-Security-Policy' ancestor checks, for instance).
|
|
|
|
* `'connectionaborted'` - A connection timed out as a result of not receiving an ACK for data sent.
|
|
|
|
* `'connectionclosed'` - A connection was closed (corresponding to a TCP FIN).
|
|
|
|
* `'connectionfailed'` - A connection attempt failed.
|
|
|
|
* `'connectionrefused'` - A connection attempt was refused.
|
|
|
|
* `'connectionreset'` - A connection was reset (corresponding to a TCP RST).
|
|
|
|
* `'internetdisconnected'` - The Internet connection has been lost.
|
|
|
|
* `'namenotresolved'` - The host name could not be resolved.
|
|
|
|
* `'timedout'` - An operation timed out.
|
|
|
|
* `'failed'` - A generic failure occurred.
|
2021-01-07 11:46:05 -08:00
|
|
|
|
|
|
|
## async method: Route.continue
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-08 15:00:14 -08:00
|
|
|
* langs:
|
2021-02-03 13:40:58 -08:00
|
|
|
- alias-java: resume
|
2021-01-08 15:00:14 -08:00
|
|
|
- alias-python: continue_
|
2021-01-07 11:46:05 -08:00
|
|
|
|
|
|
|
Continues route's request with optional overrides.
|
|
|
|
|
2022-11-21 10:40:21 -08:00
|
|
|
**Usage**
|
|
|
|
|
2021-01-07 11:46:05 -08:00
|
|
|
```js
|
|
|
|
await page.route('**/*', (route, request) => {
|
|
|
|
// Override headers
|
|
|
|
const headers = {
|
|
|
|
...request.headers(),
|
2022-06-13 16:56:16 -08:00
|
|
|
foo: 'foo-value', // set "foo" header
|
|
|
|
bar: undefined, // remove "bar" header
|
2021-01-07 11:46:05 -08:00
|
|
|
};
|
|
|
|
route.continue({headers});
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2021-02-25 22:03:39 -08:00
|
|
|
```java
|
|
|
|
page.route("**/*", route -> {
|
|
|
|
// Override headers
|
|
|
|
Map<String, String> headers = new HashMap<>(route.request().headers());
|
2022-06-13 16:56:16 -08:00
|
|
|
headers.put("foo", "foo-value"); // set "foo" header
|
|
|
|
headers.remove("bar"); // remove "bar" header
|
2021-03-05 13:50:34 -08:00
|
|
|
route.resume(new Route.ResumeOptions().setHeaders(headers));
|
2021-02-25 22:03:39 -08:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2021-01-14 07:48:56 -08:00
|
|
|
```python async
|
|
|
|
async def handle(route, request):
|
|
|
|
# override headers
|
|
|
|
headers = {
|
|
|
|
**request.headers,
|
2022-06-13 16:56:16 -08:00
|
|
|
"foo": "foo-value" # set "foo" header
|
|
|
|
"bar": None # remove "bar" header
|
2021-01-14 07:48:56 -08:00
|
|
|
}
|
2021-04-26 08:46:17 -07:00
|
|
|
await route.continue_(headers=headers)
|
2021-01-14 07:48:56 -08:00
|
|
|
}
|
|
|
|
await page.route("**/*", handle)
|
|
|
|
```
|
|
|
|
|
|
|
|
```python sync
|
|
|
|
def handle(route, request):
|
|
|
|
# override headers
|
|
|
|
headers = {
|
|
|
|
**request.headers,
|
2022-06-13 16:56:16 -08:00
|
|
|
"foo": "foo-value" # set "foo" header
|
|
|
|
"bar": None # remove "bar" header
|
2021-01-14 07:48:56 -08:00
|
|
|
}
|
2021-04-26 08:46:17 -07:00
|
|
|
route.continue_(headers=headers)
|
2021-01-14 07:48:56 -08:00
|
|
|
}
|
|
|
|
page.route("**/*", handle)
|
|
|
|
```
|
|
|
|
|
2021-05-14 16:49:14 +02:00
|
|
|
```csharp
|
|
|
|
await page.RouteAsync("**/*", route =>
|
|
|
|
{
|
|
|
|
var headers = new Dictionary<string, string>(route.Request.Headers) { { "foo", "bar" } };
|
|
|
|
headers.Remove("origin");
|
2021-05-17 20:10:32 -07:00
|
|
|
route.ContinueAsync(headers);
|
2021-05-14 16:49:14 +02:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2021-01-08 16:17:54 -08:00
|
|
|
### option: Route.continue.url
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-08 16:17:54 -08:00
|
|
|
- `url` <[string]>
|
|
|
|
|
|
|
|
If set changes the request URL. New URL must have same protocol as original one.
|
|
|
|
|
|
|
|
### option: Route.continue.method
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-08 16:17:54 -08:00
|
|
|
- `method` <[string]>
|
|
|
|
|
|
|
|
If set changes the request method (e.g. GET or POST)
|
|
|
|
|
|
|
|
### option: Route.continue.postData
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2022-11-15 15:46:54 -08:00
|
|
|
* langs: js, python, java
|
2021-01-08 16:17:54 -08:00
|
|
|
- `postData` <[string]|[Buffer]>
|
|
|
|
|
|
|
|
If set changes the post data of request
|
|
|
|
|
2022-11-15 15:46:54 -08:00
|
|
|
### option: Route.continue.postData
|
|
|
|
* since: v1.8
|
|
|
|
* langs: csharp
|
|
|
|
- `postData` <[Buffer]>
|
|
|
|
|
|
|
|
If set changes the post data of request
|
|
|
|
|
2021-01-08 16:17:54 -08:00
|
|
|
### option: Route.continue.headers
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-08 16:17:54 -08:00
|
|
|
- `headers` <[Object]<[string], [string]>>
|
|
|
|
|
|
|
|
If set changes the request HTTP headers. Header values will be converted to a string.
|
2021-01-07 11:46:05 -08:00
|
|
|
|
2022-06-13 11:30:51 -08:00
|
|
|
## async method: Route.fallback
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.23
|
2022-06-13 11:30:51 -08:00
|
|
|
|
2022-06-13 16:56:16 -08:00
|
|
|
When several routes match the given pattern, they run in the order opposite to their registration.
|
2022-06-28 22:46:54 +02:00
|
|
|
That way the last registered route can always override all the previous ones. In the example below,
|
2022-06-13 16:56:16 -08:00
|
|
|
request will be handled by the bottom-most handler first, then it'll fall back to the previous one and
|
|
|
|
in the end will be aborted by the first registered route.
|
|
|
|
|
2022-11-21 10:40:21 -08:00
|
|
|
**Usage**
|
|
|
|
|
2022-06-13 16:56:16 -08:00
|
|
|
```js
|
|
|
|
await page.route('**/*', route => {
|
|
|
|
// Runs last.
|
|
|
|
route.abort();
|
|
|
|
});
|
|
|
|
await page.route('**/*', route => {
|
|
|
|
// Runs second.
|
|
|
|
route.fallback();
|
|
|
|
});
|
|
|
|
await page.route('**/*', route => {
|
|
|
|
// Runs first.
|
|
|
|
route.fallback();
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
```java
|
|
|
|
page.route("**/*", route -> {
|
|
|
|
// Runs last.
|
|
|
|
route.abort();
|
|
|
|
});
|
|
|
|
|
|
|
|
page.route("**/*", route -> {
|
|
|
|
// Runs second.
|
|
|
|
route.fallback();
|
|
|
|
});
|
|
|
|
|
|
|
|
page.route("**/*", route -> {
|
|
|
|
// Runs first.
|
|
|
|
route.fallback();
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
```python async
|
|
|
|
await page.route("**/*", lambda route: route.abort()) # Runs last.
|
|
|
|
await page.route("**/*", lambda route: route.fallback()) # Runs second.
|
|
|
|
await page.route("**/*", lambda route: route.fallback()) # Runs first.
|
|
|
|
```
|
|
|
|
|
|
|
|
```python sync
|
|
|
|
page.route("**/*", lambda route: route.abort()) # Runs last.
|
|
|
|
page.route("**/*", lambda route: route.fallback()) # Runs second.
|
|
|
|
page.route("**/*", lambda route: route.fallback()) # Runs first.
|
|
|
|
```
|
|
|
|
|
|
|
|
```csharp
|
|
|
|
await page.RouteAsync("**/*", route => {
|
|
|
|
// Runs last.
|
|
|
|
await route.AbortAsync();
|
|
|
|
});
|
|
|
|
|
|
|
|
await page.RouteAsync("**/*", route => {
|
|
|
|
// Runs second.
|
|
|
|
await route.FallbackAsync();
|
|
|
|
});
|
|
|
|
|
|
|
|
await page.RouteAsync("**/*", route => {
|
|
|
|
// Runs first.
|
|
|
|
await route.FallbackAsync();
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
Registering multiple routes is useful when you want separate handlers to
|
|
|
|
handle different kinds of requests, for example API calls vs page resources or
|
|
|
|
GET requests vs POST requests as in the example below.
|
2022-06-13 11:30:51 -08:00
|
|
|
|
|
|
|
```js
|
|
|
|
// Handle GET requests.
|
|
|
|
await page.route('**/*', route => {
|
|
|
|
if (route.request().method() !== 'GET') {
|
|
|
|
route.fallback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Handling GET only.
|
|
|
|
// ...
|
|
|
|
});
|
|
|
|
|
|
|
|
// Handle POST requests.
|
|
|
|
await page.route('**/*', route => {
|
|
|
|
if (route.request().method() !== 'POST') {
|
|
|
|
route.fallback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Handling POST only.
|
|
|
|
// ...
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
```java
|
|
|
|
// Handle GET requests.
|
|
|
|
page.route("**/*", route -> {
|
|
|
|
if (!route.request().method().equals("GET")) {
|
|
|
|
route.fallback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Handling GET only.
|
|
|
|
// ...
|
|
|
|
});
|
|
|
|
|
|
|
|
// Handle POST requests.
|
|
|
|
page.route("**/*", route -> {
|
|
|
|
if (!route.request().method().equals("POST")) {
|
|
|
|
route.fallback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Handling POST only.
|
|
|
|
// ...
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
```python async
|
|
|
|
# Handle GET requests.
|
|
|
|
def handle_post(route):
|
|
|
|
if route.request.method != "GET":
|
|
|
|
route.fallback()
|
|
|
|
return
|
|
|
|
# Handling GET only.
|
|
|
|
# ...
|
|
|
|
|
|
|
|
# Handle POST requests.
|
|
|
|
def handle_post(route):
|
|
|
|
if route.request.method != "POST":
|
|
|
|
route.fallback()
|
|
|
|
return
|
|
|
|
# Handling POST only.
|
|
|
|
# ...
|
|
|
|
|
|
|
|
await page.route("**/*", handle_get)
|
|
|
|
await page.route("**/*", handle_post)
|
|
|
|
```
|
|
|
|
|
|
|
|
```python sync
|
|
|
|
# Handle GET requests.
|
|
|
|
def handle_post(route):
|
|
|
|
if route.request.method != "GET":
|
|
|
|
route.fallback()
|
|
|
|
return
|
|
|
|
# Handling GET only.
|
|
|
|
# ...
|
|
|
|
|
|
|
|
# Handle POST requests.
|
|
|
|
def handle_post(route):
|
|
|
|
if route.request.method != "POST":
|
|
|
|
route.fallback()
|
|
|
|
return
|
|
|
|
# Handling POST only.
|
|
|
|
# ...
|
|
|
|
|
|
|
|
page.route("**/*", handle_get)
|
|
|
|
page.route("**/*", handle_post)
|
|
|
|
```
|
|
|
|
|
|
|
|
```csharp
|
|
|
|
// Handle GET requests.
|
|
|
|
await page.RouteAsync("**/*", route => {
|
|
|
|
if (route.Request.Method != "GET") {
|
|
|
|
await route.FallbackAsync();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Handling GET only.
|
|
|
|
// ...
|
|
|
|
});
|
|
|
|
|
|
|
|
// Handle POST requests.
|
|
|
|
await page.RouteAsync("**/*", route => {
|
|
|
|
if (route.Request.Method != "POST") {
|
|
|
|
await route.FallbackAsync();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Handling POST only.
|
|
|
|
// ...
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-06-13 16:56:16 -08:00
|
|
|
One can also modify request while falling back to the subsequent handler, that way intermediate
|
|
|
|
route handler can modify url, method, headers and postData of the request.
|
|
|
|
|
|
|
|
```js
|
|
|
|
await page.route('**/*', (route, request) => {
|
|
|
|
// Override headers
|
|
|
|
const headers = {
|
|
|
|
...request.headers(),
|
|
|
|
foo: 'foo-value', // set "foo" header
|
|
|
|
bar: undefined, // remove "bar" header
|
|
|
|
};
|
|
|
|
route.fallback({headers});
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
```java
|
|
|
|
page.route("**/*", route -> {
|
|
|
|
// Override headers
|
|
|
|
Map<String, String> headers = new HashMap<>(route.request().headers());
|
|
|
|
headers.put("foo", "foo-value"); // set "foo" header
|
|
|
|
headers.remove("bar"); // remove "bar" header
|
|
|
|
route.fallback(new Route.ResumeOptions().setHeaders(headers));
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
```python async
|
|
|
|
async def handle(route, request):
|
|
|
|
# override headers
|
|
|
|
headers = {
|
|
|
|
**request.headers,
|
|
|
|
"foo": "foo-value" # set "foo" header
|
|
|
|
"bar": None # remove "bar" header
|
|
|
|
}
|
|
|
|
await route.fallback(headers=headers)
|
|
|
|
}
|
|
|
|
await page.route("**/*", handle)
|
|
|
|
```
|
|
|
|
|
|
|
|
```python sync
|
|
|
|
def handle(route, request):
|
|
|
|
# override headers
|
|
|
|
headers = {
|
|
|
|
**request.headers,
|
|
|
|
"foo": "foo-value" # set "foo" header
|
|
|
|
"bar": None # remove "bar" header
|
|
|
|
}
|
|
|
|
route.fallback(headers=headers)
|
|
|
|
}
|
|
|
|
page.route("**/*", handle)
|
|
|
|
```
|
|
|
|
|
|
|
|
```csharp
|
|
|
|
await page.RouteAsync("**/*", route =>
|
|
|
|
{
|
|
|
|
var headers = new Dictionary<string, string>(route.Request.Headers) { { "foo", "foo-value" } };
|
|
|
|
headers.Remove("bar");
|
|
|
|
route.FallbackAsync(headers);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### option: Route.fallback.url
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.23
|
2022-06-13 16:56:16 -08:00
|
|
|
- `url` <[string]>
|
|
|
|
|
|
|
|
If set changes the request URL. New URL must have same protocol as original one. Changing the URL won't
|
|
|
|
affect the route matching, all the routes are matched using the original request URL.
|
|
|
|
|
|
|
|
### option: Route.fallback.method
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.23
|
2022-06-13 16:56:16 -08:00
|
|
|
- `method` <[string]>
|
|
|
|
|
|
|
|
If set changes the request method (e.g. GET or POST)
|
|
|
|
|
|
|
|
### option: Route.fallback.postData
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.23
|
2022-11-15 15:46:54 -08:00
|
|
|
* langs: js, python, java
|
2022-06-13 16:56:16 -08:00
|
|
|
- `postData` <[string]|[Buffer]>
|
2022-11-15 15:46:54 -08:00
|
|
|
|
|
|
|
If set changes the post data of request
|
|
|
|
|
|
|
|
### option: Route.fallback.postData
|
|
|
|
* since: v1.23
|
|
|
|
* langs: csharp
|
|
|
|
- `postData` <[Buffer]>
|
2022-06-13 16:56:16 -08:00
|
|
|
|
|
|
|
If set changes the post data of request
|
|
|
|
|
|
|
|
### option: Route.fallback.headers
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.23
|
2022-06-13 16:56:16 -08:00
|
|
|
- `headers` <[Object]<[string], [string]>>
|
|
|
|
|
|
|
|
If set changes the request HTTP headers. Header values will be converted to a string.
|
|
|
|
|
2021-01-07 11:46:05 -08:00
|
|
|
## async method: Route.fulfill
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-07 11:46:05 -08:00
|
|
|
|
|
|
|
Fulfills route's request with given response.
|
|
|
|
|
2022-11-21 10:40:21 -08:00
|
|
|
**Usage**
|
|
|
|
|
2021-01-07 11:46:05 -08:00
|
|
|
An example of fulfilling all requests with 404 responses:
|
|
|
|
|
|
|
|
```js
|
|
|
|
await page.route('**/*', route => {
|
|
|
|
route.fulfill({
|
|
|
|
status: 404,
|
|
|
|
contentType: 'text/plain',
|
|
|
|
body: 'Not Found!'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2021-02-25 22:03:39 -08:00
|
|
|
```java
|
|
|
|
page.route("**/*", route -> {
|
|
|
|
route.fulfill(new Route.FulfillOptions()
|
2021-03-05 13:50:34 -08:00
|
|
|
.setStatus(404)
|
|
|
|
.setContentType("text/plain")
|
|
|
|
.setBody("Not Found!"));
|
2021-02-25 22:03:39 -08:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2021-01-14 07:48:56 -08:00
|
|
|
```python async
|
|
|
|
await page.route("**/*", lambda route: route.fulfill(
|
|
|
|
status=404,
|
|
|
|
content_type="text/plain",
|
|
|
|
body="not found!"))
|
|
|
|
```
|
|
|
|
|
|
|
|
```python sync
|
|
|
|
page.route("**/*", lambda route: route.fulfill(
|
|
|
|
status=404,
|
|
|
|
content_type="text/plain",
|
|
|
|
body="not found!"))
|
|
|
|
```
|
|
|
|
|
2021-05-14 16:49:14 +02:00
|
|
|
```csharp
|
|
|
|
await page.RouteAsync("**/*", route => route.FulfillAsync(
|
|
|
|
status: 404,
|
2022-04-06 19:02:10 -07:00
|
|
|
contentType: "text/plain",
|
2021-05-14 16:49:14 +02:00
|
|
|
body: "Not Found!"));
|
|
|
|
```
|
|
|
|
|
2021-01-07 11:46:05 -08:00
|
|
|
An example of serving static file:
|
|
|
|
|
|
|
|
```js
|
|
|
|
await page.route('**/xhr_endpoint', route => route.fulfill({ path: 'mock_data.json' }));
|
|
|
|
```
|
|
|
|
|
2021-02-25 22:03:39 -08:00
|
|
|
```java
|
|
|
|
page.route("**/xhr_endpoint", route -> route.fulfill(
|
2021-08-19 11:24:38 -07:00
|
|
|
new Route.FulfillOptions().setPath(Paths.get("mock_data.json"))));
|
2021-02-25 22:03:39 -08:00
|
|
|
```
|
|
|
|
|
2021-01-14 07:48:56 -08:00
|
|
|
```python async
|
|
|
|
await page.route("**/xhr_endpoint", lambda route: route.fulfill(path="mock_data.json"))
|
|
|
|
```
|
|
|
|
|
|
|
|
```python sync
|
|
|
|
page.route("**/xhr_endpoint", lambda route: route.fulfill(path="mock_data.json"))
|
|
|
|
```
|
|
|
|
|
2021-05-14 16:49:14 +02:00
|
|
|
```csharp
|
2021-05-19 17:19:25 -07:00
|
|
|
await page.RouteAsync("**/xhr_endpoint", route => route.FulfillAsync(new RouteFulfillOptions { Path = "mock_data.json" }));
|
2021-05-14 16:49:14 +02:00
|
|
|
```
|
|
|
|
|
2021-01-08 16:17:54 -08:00
|
|
|
### option: Route.fulfill.status
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-08 16:17:54 -08:00
|
|
|
- `status` <[int]>
|
|
|
|
|
|
|
|
Response status code, defaults to `200`.
|
|
|
|
|
|
|
|
### option: Route.fulfill.headers
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-08 16:17:54 -08:00
|
|
|
- `headers` <[Object]<[string], [string]>>
|
|
|
|
|
|
|
|
Response headers. Header values will be converted to a string.
|
|
|
|
|
|
|
|
### option: Route.fulfill.contentType
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-08 16:17:54 -08:00
|
|
|
- `contentType` <[string]>
|
|
|
|
|
|
|
|
If set, equals to setting `Content-Type` response header.
|
|
|
|
|
|
|
|
### option: Route.fulfill.body
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-02-03 14:56:17 -08:00
|
|
|
* langs: js, python
|
2021-01-08 16:17:54 -08:00
|
|
|
- `body` <[string]|[Buffer]>
|
|
|
|
|
|
|
|
Response body.
|
|
|
|
|
2021-02-03 14:56:17 -08:00
|
|
|
### option: Route.fulfill.body
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-02-03 14:56:17 -08:00
|
|
|
* langs: csharp, java
|
|
|
|
- `body` <[string]>
|
|
|
|
|
|
|
|
Optional response body as text.
|
|
|
|
|
|
|
|
### option: Route.fulfill.bodyBytes
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.9
|
2021-02-03 14:56:17 -08:00
|
|
|
* langs: csharp, java
|
|
|
|
- `bodyBytes` <[Buffer]>
|
|
|
|
|
|
|
|
Optional response body as raw bytes.
|
|
|
|
|
2021-01-08 16:17:54 -08:00
|
|
|
### option: Route.fulfill.path
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-08 16:17:54 -08:00
|
|
|
- `path` <[path]>
|
2021-01-07 11:46:05 -08:00
|
|
|
|
2021-01-14 07:48:56 -08:00
|
|
|
File path to respond with. The content type will be inferred from file extension. If `path` is a relative path, then it
|
|
|
|
is resolved relative to the current working directory.
|
2021-01-07 11:46:05 -08:00
|
|
|
|
2021-09-10 18:36:55 -07:00
|
|
|
### option: Route.fulfill.response
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.15
|
2022-06-20 15:19:54 -07:00
|
|
|
- `response` <[APIResponse]>
|
2021-09-10 18:36:55 -07:00
|
|
|
|
2022-06-20 15:19:54 -07:00
|
|
|
[APIResponse] to fulfill route's request with. Individual fields of the response (such as headers) can be overridden using fulfill options.
|
2021-09-10 18:36:55 -07:00
|
|
|
|
2021-01-07 11:46:05 -08:00
|
|
|
## method: Route.request
|
2022-07-05 16:24:50 -08:00
|
|
|
* since: v1.8
|
2021-01-07 11:46:05 -08:00
|
|
|
- returns: <[Request]>
|
|
|
|
|
|
|
|
A request to be routed.
|