-
Notifications
You must be signed in to change notification settings - Fork 216
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 support for AbortSignal
to all API methods
#339
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor comment about the docs, but otherwise, I think this looks good.
| `options.route` | `string` | Required. REST API endpoint path. | | ||
| `options.params` | `object` | URL query parameters for the given route. | | ||
| `options.method` | `string` | HTTP method for the given route. | | ||
| `options.headers` | `object` | Additional HTTP headers for the given route. | | ||
| `options.data` | `object | FormData` | Request body. | | ||
| `options.signal` | `AbortSignal` | Optional `AbortSignal`. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you fix the formatting here so the table's dividers align vertically, please?
This PR adds support for passing
AbortSignal
to all API methods that make HTTP requests, these are passed directly into the nativefetch()
implementation, so it's up to the user to handle theAbortError
raised, if any.The
paginate
function also checks to see whether the signal was aborted before proceeding to the next iteration. If so it returns immediately to avoid making a redundant fetch call.This allows the client to take advantage of various frameworks that provide an
AbortSignal
instance to tear down any in flight requests.