Skip to content

Commit 78e6d92

Browse files
Jake ChampionJakeChampion
authored andcommitted
fix: Add documentation for FetchEvent, FetchEvent.prototype.respondWith, and FetchEvent.prototype.waitUntil
1 parent f53a06e commit 78e6d92

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
# FetchEvent
8+
9+
This is the event type for `fetch` events. It contains information about the fetch, including the request and how the receiver will treat the response.
10+
It provides the [`event.respondWith()`](./prototype/respondWith.mdx) method, which allows us to provide a response to this fetch.
11+
12+
## Instance properties
13+
14+
- `FetchEvent.request` _**readonly**_
15+
- : The `Request` that was recieved by the application.
16+
- `FetchEvent.client` _**readonly**_
17+
- : Information about the downstream client that made the request.
18+
- `FetchEvent.client.address` _**readonly**_
19+
- : A string representation of the IPv4 or IPv6 address of the downstream client.
20+
- `FetchEvent.client.geo` _**readonly**_
21+
- : A [geolocation dictionary](../../fastly:geolocation/getGeolocationForIpAddress.mdx) corresponding to the IP address of the downstream client.
22+
23+
## Instance methods
24+
25+
- [`FetchEvent.respondWith()`](./prototype/respondWith.mdx)
26+
- : Provide (a promise for) a response for this request.
27+
- [`FetchEvent.waitUntil()`](./prototype/waitUntil.mdx)
28+
- : Extends the lifetime of the event. Used to notify the host environment of tasks that extend beyond the returning of a response, such as streaming and caching.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
# FetchEvent.respondWith()
8+
9+
The **`respondWith()`** method allows you to provide a promise for a [`Response`](../../Response/Response.mdx) to send back to the client which made the incoming request to your application.
10+
11+
## Syntax
12+
13+
```js
14+
respondWith(response)
15+
```
16+
17+
### Parameters
18+
19+
- `response`
20+
- : A [`Response`](../../Response/Response.mdx) or a [`Promise`](../../Promise/Promise.mdx) that resolves to a
21+
[`Response`](../../Response/Response.mdx). Otherwise, a network error is returned to Fetch.
22+
23+
### Return value
24+
25+
None `undefined`.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
# FetchEvent.waitUntil()
8+
9+
10+
The **`waitUntil()`** method tells the host environment that work is ongoing until the promise settles, and it shouldn't terminate
11+
the application if it wants that work to complete.
12+
13+
The `waitUntil()` method must be initially called within the event callback,
14+
but after that it can be called multiple times, until all the promises passed to it
15+
settle.
16+
17+
## Syntax
18+
19+
```js
20+
waitUntil(promise)
21+
```
22+
23+
### Parameters
24+
25+
A [`Promise`](../../Promise/Promise.mdx).
26+
27+
### Return value
28+
29+
None `undefined`.

0 commit comments

Comments
 (0)