Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AbortSignal type definition & update documentation #3

Merged
merged 2 commits into from
Nov 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface HonokaRequestOptions {
cache?: HonokaRequestCache;
redirect?: HonokaRequestRedirect;
integrity?: string;
signal?: AbortSignal | null;
window?: null;
follow?: number;
baseURL?: string;
Expand Down