storyblok / storyblok-js-client

Universal JavaScript client for Storyblok's API
MIT License
129 stars 87 forks source link

Provide a custom fetch function for the js client #573

Closed SebbeJohansson closed 1 year ago

SebbeJohansson commented 1 year ago

It would be very helpful for a various number of usecases to allow for the js client to use a custom fetch function that is provided into the client

Expected Behavior

I expect the js client to allow for an option that is a custom fetch function that the user creates and provides into it.

Psuedo example:

import { fetch } from "fastly";
const fastlyComputeFetch = fetch("slugtofetch", {backend: 'storyblokapi.net'})
const Storyblok = new StoryblokClient({
  oauthToken: <YOUR_OAUTH_TOKEN>,
}, fetchFunction: fastlyComputeFetch );

Current Behavior

Right now, nothing like that exists, which means that for use cases that require a specific fetch function or a wrapper over the native fetch function, there is no solution.

Use cases

Alternative solutions

Original discussion on discord: https://discord.com/channels/700316478792138842/1110132991268753428/1112802240424583320

SebbeJohansson commented 1 year ago

This idea was born from the issues we are having in a nuxt2 project. See part of that discussion here: https://github.com/storyblok/storyblok-js-client/issues/554

thiagosaife commented 1 year ago

@SebbeJohansson This will be converted into a Feature Request. Thank you for your help, sir.

SebbeJohansson commented 1 year ago

Thanks for listening!

thiagosaife commented 1 year ago

Thank you for helping us with your time and suggestions.