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
2024-08-06 11:35:53 -07:00
Sends route's request to the network with optional overrides.
2021-01-07 11:46:05 -08:00
2022-11-21 10:40:21 -08:00
**Usage**
2021-01-07 11:46:05 -08:00
```js
2023-12-21 09:57:35 -08:00
await page.route('**/*', async (route, request) => {
2021-01-07 11:46:05 -08:00
// 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
};
2023-12-21 09:57:35 -08:00
await route.continue({ headers });
2021-01-07 11:46:05 -08:00
});
```
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,
2023-06-27 11:53:27 +02:00
"foo": "foo-value", # set "foo" header
2022-06-13 16:56:16 -08:00
"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)
2022-11-30 17:26:19 -08:00
2021-01-14 07:48:56 -08:00
await page.route("**/*", handle)
```
```python sync
def handle(route, request):
# override headers
headers = {
**request.headers,
2023-06-27 11:53:27 +02:00
"foo": "foo-value", # set "foo" header
2022-06-13 16:56:16 -08:00
"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)
2022-11-30 17:26:19 -08:00
2021-01-14 07:48:56 -08:00
page.route("**/*", handle)
```
2021-05-14 16:49:14 +02:00
```csharp
2024-02-14 17:57:12 +01:00
await page.RouteAsync("**/*", async route =>
2021-05-14 16:49:14 +02:00
{
var headers = new Dictionary< string , string > (route.Request.Headers) { { "foo", "bar" } };
headers.Remove("origin");
2024-02-14 17:57:12 +01:00
await route.ContinueAsync(new() { Headers = headers });
2021-05-14 16:49:14 +02:00
});
```
2023-02-01 16:55:03 -08:00
**Details**
2024-10-07 13:52:55 -07:00
The [`option: headers` ] option applies to both the routed request and any redirects it initiates. However, [`option: url` ], [`option: method` ], and [`option: postData` ] only apply to the original request and are not carried over to redirected requests.
2023-02-01 16:55:03 -08:00
2024-08-06 11:35:53 -07:00
[`method: Route.continue` ] will immediately send the request to the network, other matching handlers won't be invoked. Use [`method: Route.fallback` ] If you want next matching handler in the chain to be invoked.
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]>
2022-11-30 17:26:19 -08:00
If set changes the request method (e.g. GET or POST).
2021-01-08 16:17:54 -08:00
### option: Route.continue.postData
2022-07-05 16:24:50 -08:00
* since: v1.8
2022-12-16 11:14:29 -08:00
* langs: js, python
2022-12-13 14:01:39 -08:00
- `postData` < [string]|[Buffer]|[Serializable]>
2021-01-08 16:17:54 -08:00
2022-11-30 17:26:19 -08:00
If set changes the post data of request.
2021-01-08 16:17:54 -08:00
2022-12-16 11:14:29 -08:00
### option: Route.continue.postData
* since: v1.8
* langs: java
- `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]>
2022-11-30 17:26:19 -08:00
If set changes the post data of request.
2022-11-15 15:46:54 -08:00
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
2024-08-06 11:35:53 -07:00
Continues route's request with optional overrides. The method is similar to [`method: Route.continue` ] with the difference that other matching handlers will be invoked before sending the request.
**Usage**
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.
```js
2023-12-21 09:57:35 -08:00
await page.route('**/*', async route => {
2022-06-13 16:56:16 -08:00
// Runs last.
2023-12-21 09:57:35 -08:00
await route.abort();
2022-06-13 16:56:16 -08:00
});
2023-12-21 09:57:35 -08:00
await page.route('**/*', async route => {
2022-06-13 16:56:16 -08:00
// Runs second.
2023-12-21 09:57:35 -08:00
await route.fallback();
2022-06-13 16:56:16 -08:00
});
2023-12-21 09:57:35 -08:00
await page.route('**/*', async route => {
2022-06-13 16:56:16 -08:00
// Runs first.
2023-12-21 09:57:35 -08:00
await route.fallback();
2022-06-13 16:56:16 -08:00
});
```
```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.
2023-12-21 09:57:35 -08:00
await page.route('**/*', async route => {
2022-06-13 11:30:51 -08:00
if (route.request().method() !== 'GET') {
2023-12-21 09:57:35 -08:00
await route.fallback();
2022-06-13 11:30:51 -08:00
return;
}
// Handling GET only.
// ...
});
// Handle POST requests.
2023-12-21 09:57:35 -08:00
await page.route('**/*', async route => {
2022-06-13 11:30:51 -08:00
if (route.request().method() !== 'POST') {
2023-12-21 09:57:35 -08:00
await route.fallback();
2022-06-13 11:30:51 -08:00
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.
2024-02-14 17:57:12 +01:00
async def handle_get(route):
2022-06-13 11:30:51 -08:00
if route.request.method != "GET":
2024-02-14 17:57:12 +01:00
await route.fallback()
2022-06-13 11:30:51 -08:00
return
# Handling GET only.
# ...
# Handle POST requests.
2024-02-14 17:57:12 +01:00
async def handle_post(route):
2022-06-13 11:30:51 -08:00
if route.request.method != "POST":
2024-02-14 17:57:12 +01:00
await route.fallback()
2022-06-13 11:30:51 -08:00
return
# Handling POST only.
# ...
await page.route("**/*", handle_get)
await page.route("**/*", handle_post)
```
```python sync
# Handle GET requests.
2023-05-14 17:52:11 +03:00
def handle_get(route):
2022-06-13 11:30:51 -08:00
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
2023-12-21 09:57:35 -08:00
await page.route('**/*', async (route, request) => {
2022-06-13 16:56:16 -08:00
// Override headers
const headers = {
...request.headers(),
foo: 'foo-value', // set "foo" header
bar: undefined, // remove "bar" header
};
2023-12-21 09:57:35 -08:00
await route.fallback({ headers });
2022-06-13 16:56:16 -08:00
});
```
```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,
2023-06-27 11:53:27 +02:00
"foo": "foo-value", # set "foo" header
2022-06-13 16:56:16 -08:00
"bar": None # remove "bar" header
}
await route.fallback(headers=headers)
2022-11-30 17:26:19 -08:00
2022-06-13 16:56:16 -08:00
await page.route("**/*", handle)
```
```python sync
def handle(route, request):
# override headers
headers = {
**request.headers,
2023-06-27 11:53:27 +02:00
"foo": "foo-value", # set "foo" header
2022-06-13 16:56:16 -08:00
"bar": None # remove "bar" header
}
route.fallback(headers=headers)
2022-11-30 17:26:19 -08:00
2022-06-13 16:56:16 -08:00
page.route("**/*", handle)
```
```csharp
2024-02-14 17:57:12 +01:00
await page.RouteAsync("**/*", async route =>
2022-06-13 16:56:16 -08:00
{
var headers = new Dictionary< string , string > (route.Request.Headers) { { "foo", "foo-value" } };
headers.Remove("bar");
2024-02-14 17:57:12 +01:00
await route.FallbackAsync(new() { Headers = headers });
2022-06-13 16:56:16 -08:00
});
```
2024-08-06 11:35:53 -07:00
Use [`method: Route.continue` ] to immediately send the request to the network, other matching handlers won't be invoked in that case.
2022-06-13 16:56:16 -08:00
### 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]>
2022-11-30 17:26:19 -08:00
If set changes the request method (e.g. GET or POST).
2022-06-13 16:56:16 -08:00
### option: Route.fallback.postData
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-12-16 11:14:29 -08:00
* langs: js, python
2022-12-13 14:01:39 -08:00
- `postData` < [string]|[Buffer]|[Serializable]>
2022-11-15 15:46:54 -08:00
2022-11-30 17:26:19 -08:00
If set changes the post data of request.
2022-11-15 15:46:54 -08:00
2022-12-16 11:14:29 -08:00
### option: Route.fallback.postData
* since: v1.23
* langs: java
- `postData` < [string]|[Buffer]>
If set changes the post data of request.
2022-11-15 15:46:54 -08:00
### option: Route.fallback.postData
* since: v1.23
* langs: csharp
- `postData` < [Buffer]>
2022-06-13 16:56:16 -08:00
2022-11-30 17:26:19 -08:00
If set changes the post data of request.
2022-06-13 16:56:16 -08:00
### 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.
2022-11-30 17:26:19 -08:00
## async method: Route.fetch
* since: v1.29
- returns: < [APIResponse]>
Performs the request and fetches result without fulfilling it, so that the response
could be modified and then fulfilled.
**Usage**
```js
await page.route('https://dog.ceo/api/breeds/list/all', async route => {
const response = await route.fetch();
const json = await response.json();
json.message['big_red_dog'] = [];
await route.fulfill({ response, json });
});
```
```java
page.route("https://dog.ceo/api/breeds/list/all", route -> {
APIResponse response = route.fetch();
JsonObject json = new Gson().fromJson(response.text(), JsonObject.class);
2022-11-30 19:29:14 -08:00
JsonObject message = itemObj.get("json").getAsJsonObject();
message.set("big_red_dog", new JsonArray());
2022-11-30 17:26:19 -08:00
route.fulfill(new Route.FulfillOptions()
.setResponse(response)
.setBody(json.toString()));
});
```
```python async
async def handle(route):
2023-01-04 04:05:09 +09:00
response = await route.fetch()
2022-11-30 17:26:19 -08:00
json = await response.json()
2022-11-30 19:29:14 -08:00
json["message"]["big_red_dog"] = []
2022-11-30 17:26:19 -08:00
await route.fulfill(response=response, json=json)
await page.route("https://dog.ceo/api/breeds/list/all", handle)
```
```python sync
def handle(route):
2023-01-04 04:05:09 +09:00
response = route.fetch()
2022-11-30 17:26:19 -08:00
json = response.json()
2022-11-30 19:29:14 -08:00
json["message"]["big_red_dog"] = []
2022-11-30 17:26:19 -08:00
route.fulfill(response=response, json=json)
page.route("https://dog.ceo/api/breeds/list/all", handle)
```
```csharp
await page.RouteAsync("https://dog.ceo/api/breeds/list/all", async route =>
{
var response = await route.FetchAsync();
dynamic json = await response.JsonAsync();
2022-11-30 19:29:14 -08:00
json.message.big_red_dog = new string[] {};
2022-11-30 17:26:19 -08:00
await route.FulfillAsync(new() { Response = response, Json = json });
});
```
2023-02-01 16:55:03 -08:00
**Details**
Note that [`option: headers` ] option will apply to the fetched request as well as any redirects initiated by it. If you want to only apply [`option: headers` ] to the original request, but not to redirects, look into [`method: Route.continue` ] instead.
2022-11-30 17:26:19 -08:00
### option: Route.fetch.url
* since: v1.29
- `url` < [string]>
If set changes the request URL. New URL must have same protocol as original one.
2023-02-16 17:02:12 -08:00
### option: Route.fetch.maxRedirects
2023-02-01 14:43:21 -08:00
* since: v1.31
2023-02-16 17:02:12 -08:00
- `maxRedirects` < [int]>
Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is exceeded.
Defaults to `20` . Pass `0` to not follow redirects.
2023-02-01 14:43:21 -08:00
2024-07-30 19:09:20 +02:00
### option: Route.fetch.maxRetries
* since: v1.46
- `maxRetries` < [int]>
Maximum number of times network errors should be retried. Currently only `ECONNRESET` error is retried. Does not retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to `0` - no retries.
2023-04-21 01:41:33 +10:00
### option: Route.fetch.timeout
* since: v1.33
- `timeout` < [float]>
Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
2022-11-30 17:26:19 -08:00
### option: Route.fetch.method
* since: v1.29
- `method` < [string]>
If set changes the request method (e.g. GET or POST).
2022-12-16 10:14:02 -08:00
### option: Route.fetch.postData
2022-12-16 11:14:29 -08:00
* langs: js, python
2022-11-30 17:26:19 -08:00
* since: v1.29
2022-12-16 10:14:02 -08:00
- `postData` < [string]|[Buffer]|[Serializable]>
Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string
and `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` header will be
set to `application/octet-stream` if not explicitly set.
2022-11-30 17:26:19 -08:00
2022-12-16 11:14:29 -08:00
### option: Route.fetch.postData
* langs: java
* since: v1.29
- `postData` < [string]|[Buffer]>
If set changes the post data of request.
2022-12-13 14:01:39 -08:00
### option: Route.fetch.postData
2022-11-30 17:26:19 -08:00
* since: v1.29
* langs: csharp
- `postData` < [Buffer]>
If set changes the post data of request.
### option: Route.fetch.headers
* since: v1.29
- `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
2023-12-21 09:57:35 -08:00
await page.route('**/*', async route => {
await route.fulfill({
2021-01-07 11:46:05 -08:00
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
2022-11-30 17:26:19 -08:00
await page.RouteAsync("**/*", route => route.FulfillAsync(new ()
{
Status = 404,
ContentType = "text/plain",
2023-06-26 18:21:14 +02:00
Body = "Not Found!"
}));
2021-05-14 16:49:14 +02:00
```
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
2022-11-30 17:26:19 -08:00
await page.RouteAsync("**/xhr_endpoint", route => route.FulfillAsync(new() { 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.
2022-11-30 17:26:19 -08:00
### option: Route.fulfill.json
* since: v1.29
2023-01-03 14:03:38 -08:00
* langs: js, python, csharp
2022-11-30 17:26:19 -08:00
- `json` < [Serializable]>
JSON response. This method will set the content type to `application/json` if not set.
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.