contentful.js icon indicating copy to clipboard operation
contentful.js copied to clipboard

Add support for cancelable requests

Open Weffe opened this issue 5 years ago • 0 comments

Since this library is using axios under the hood, I think it would be nice to provide a way to pass along the Cancellation token when making a contentful request.

Expected Behavior

I would expect to pass the cancellation token as a param on each request since that's how axios gets the cancel token.

import axios from 'axios';
import contentful from 'contentful';

const contentfulClient = contentful.createClient(contentfulConfig);
const source = CancelToken.source();

contentfulClient.getEntries({ 'fields.id': '1a2b' }, source);

// cancel the request
source.cancel(); 

Context

This feature would be very useful since we could cancel the request mid-flight if a user changes the page pre-maturely.

Weffe avatar Feb 11 '20 20:02 Weffe