Skip to content

Commit

Permalink
Add AbortSignal type definition & update documentation (#3)
Browse files Browse the repository at this point in the history
abort related
  • Loading branch information
kirainmoe authored and kokororin committed Nov 11, 2018
1 parent 8b2193f commit 18bd760
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ These are the available config options for making requests. Same as fetch() API.
// rejected.
expectedStatus(status) {
return status >= 200 && status < 400; // default
}
},
}
```

## Config Defaults

You can specify config defaults that will be applied to every request.

### Global defaults
### Global Defaults

```js
honoka.defaults.baseURL = 'https://example.com/api';
Expand Down Expand Up @@ -192,6 +192,27 @@ const unregister = honoka.interceptors.register({
unregister();
```

## Abort Operation

You can cancel a pending request manually by using `AbortController`.

```js
let abortController = new AbortController(),
signal = abortController.signal;

honoka('/100MBtest.bin', { signal })
.then((res) => {
console.log(res)
})
.catch((err) => {
console.log(err);
});

setTimeout(() => {
abortController.abort();
}, 2000);
```

## Promises

honoka depends on a native ES6 Promise implementation to be [supported](http://caniuse.com/promises).
Expand Down

0 comments on commit 18bd760

Please sign in to comment.