storyblok / storyblok-js-client

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

Possibility to add an axios adapter #71

Closed johannesdz closed 3 years ago

johannesdz commented 4 years ago

it would be very helpful, if instead of using default axios, we could pass our own axios adapter (axios functionality), where we take care of logging and other custom stuff. I know you can pass some settings, but especially logging on server side is our biggest need.

It could work like this: client: new StoryblokClient({ accessToken: ..., cache: ..., axiosAdapter: ..., }),

thiagosaife commented 3 years ago

Hi @johannesdz Do you need an http adapter to detect status? Or an interceptor? Thanks!

johannesdz commented 3 years ago

Hi @thiagosaife , as an interceptor.

thiagosaife commented 3 years ago

Hey @johannesdz, understood. Thanks!

onefriendaday commented 3 years ago

@thiagosaife made a nice feature to add an interceptor for logging: https://github.com/storyblok/storyblok-js-client/pull/76/files

but you could also overwrite the axios client by overwriting the client variable.

let clientInstance = new StoryblokClient({ accessToken: ..., cache: ... })
clientInstance.client = axios.create({...})
johannesdz commented 3 years ago

Hi @thiagosaife , yes, currently we are using it as you proposed. But then we always depent on you axios version in our whole frontend application - this is definitely something we want to avoid. It shouldn't be too crazy, since axios is already providing such a adaptor functionality.

thiagosaife commented 3 years ago

Hi @johannesdz We are updating the client to receive a function as a response interceptor. Hope it fits your needs. As soon as we updated it, I'll let you know. Best!

thiagosaife commented 3 years ago

Hi @johannesdz . You can get the latest version now. Look for the responseInterceptor on https://github.com/storyblok/storyblok-js-client/blob/master/README.md