I would like to inject an enhanced fetch to ky (fetch is a dependency to ky).
In order to use with https://github.com/AxaGuilDEv/react-oidc/tree/master/packages/context-fetch in a "functionnal way"
Is it possible to do something like :
const parsed = await ky(fetch).post('https://example.com', {json: {foo: true}}).json();
?
Regards,
Guillaume
Would it be okay if it were just a normal Ky option, as below?
const parsed = await ky.post('https://example.com', {fetch, json: {foo: true}}).json();
const myKy = ky.extend({fetch});
const parsed = await myKy.post('https://example.com', {json: {foo: true}}).json();
Yes, it is
Isn't this a duplicate of #56?
@Skayo
Yes, you're correct, it is. And the concerns that Sindre expressed there are still valid.
However, it's worth noting that since then:
fetch (e.g. https://github.com/sindresorhus/ky/commit/f107e7b92d90e4b0287846a49ba3f30d9b9ca648 and PR https://github.com/sindresorhus/ky/pull/153)It's definitely worth reconsidering this.
@sholladay
Yeah that is true.
Might even need this for a project myself.
Do you know how much work this would be?
Maybe I'll do a PR...
It should be pretty easy. You would need to update this part of the code where we execute the fetch, so that it would be something like options.fetch() instead of globals.fetch(). And you would set the default value for fetch to globals.fetch at the top of the Ky constructor, where we set our other option defaults. That should be about it, other than tests and docs.
@guillaume-chervet @sholladay
Check out #273!
Most helpful comment
Would it be okay if it were just a normal Ky option, as below?