Skip to content

Commit

Permalink
First pass at documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesplease committed Dec 8, 2017
1 parent fd5c261 commit 318e95f
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ expected to uphold this code.
* [Sending cookies](#sending-cookies)
* [Receiving cookies](#receiving-cookies)
* [Obtaining the Response URL](#obtaining-the-response-url)
* [Aborting requests](#aborting-requests)
* [Browser Support](#browser-support)

## Read this first
Expand Down Expand Up @@ -260,6 +261,47 @@ response.headers['X-Request-URL'] = request.url
This server workaround is necessary if you need reliable `response.url` in
Firefox < 32, Chrome < 37, Safari, or IE.

#### Aborting requests

This polyfill supports
[the abortable fetch API](https://developers.google.com/web/updates/2017/09/abortable-fetch).
However, aborting a fetch requires use of two additional DOM APIs:
[AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController)
and
[AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal).
Typically, browsers that do not support fetch will also not support
AbortController or AbortSignal.

Consequently, you will need to find a polyfill for these APIs to abort fetches.

Once you have an AbortController and AbortSignal polyfill in place, you can
abort a fetch like so:

```js
const controller = new AbortController()

fetch('/avatars', {
method: 'POST',
body: data,
signal: controller.signal
})
.then(
function(response) {
console.log('request succeeded', response)
},
function(ex) {
if (ex.name === 'AbortError') {
console.log('request aborted')
} else {
console.log('request failed, but it was not aborted')
}
}
)

// some time later...
controller.abort();
```

## Browser Support

- Chrome
Expand Down

0 comments on commit 318e95f

Please sign in to comment.