V8-archive: Add support for more axios settings

Created on 11 Oct 2019  路  10Comments  路  Source: directus/v8-archive

How do I add the axios-extensions extension to the project?

sdk-js

Most helpful comment

Adding support for the following fields:

  • adapter providing custom request/response adapters
  • timeout to set the basic request timeout
  • maxContentLength limit content length
  • proxy adds support for a proxy host

All 10 comments

There's no way to do this. What would this add?

We could add support for this in a future version if you're down to help out

When the request is made, if the data has already been loaded, it receives the response from the cache. I was using it to reduce requests. An axios plugin.

Sounds useful! As of right now, there's no way to inject these adapters into the underlying Axios instance. Sounds like a useful feature to have though! Would you like to work on a PR @ahmtaras ?

You can turn on support for a future release. I have no experience with Typescript. I tried to add a few times and I failed. That would be better if experienced friends developed it.

@rijkvanzanten Thank you for your attention.

This is not a feature I'll be using myself and/or will be using in Directus, so I'm afraid I won't be able to spend any time on it in the near future. For anyone willing to take this on:

The config object that's passed to the constructor of the SDK (new SDK({ config })) is passed on directly to the internal API constructor:

https://github.com/directus/sdk-js/blob/fabb420c260c4bb3148386e61c6ab9370e9e4942/src/SDK.ts#L77

We should be able to augment the axiosOptions object here with a nested object passed from config to support the OP's request here:

https://github.com/directus/sdk-js/blob/fabb420c260c4bb3148386e61c6ab9370e9e4942/src/API.ts#L93-L109

@ahmtaras You could access the Axios instance by accessing the property yourSDKInstance.api.xhr but there's no official way at the moment as @rijkvanzanten mentioned. What do you exactly need to pass? Maybe I could work on a PR :)

Thank you @janbiasi. I need to introduce the plug-in I shared above to axios in the SDK.

@ahmtaras alright, we don't support custom adapters at the moment but I could create a PR related to support more options until EOY :) I'll rename this issue to fit the CR and remove the label question as it definitely makes sense to add more configurable values.

Adding support for the following fields:

  • adapter providing custom request/response adapters
  • timeout to set the basic request timeout
  • maxContentLength limit content length
  • proxy adds support for a proxy host

Hello, I needed this again after a long time and I solved the problem as follows.

import Directus from './client'
import { cacheAdapterEnhancer, throttleAdapterEnhancer } from 'axios-extensions'

Directus.api.xhr.defaults.adapter = throttleAdapterEnhancer(cacheAdapterEnhancer(Directus.api.xhr.defaults.adapter))

This is how I reached as an example when I need to access the other settings of axios.

Directus.api.xhr.interceptors.response.use(
  response => response,
  error => {
    if (401 === error.response.status) {
      router.push('/login')
    }
  }
)

Now I'm closing the topic. Thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gitlabisbetterthangithub picture gitlabisbetterthangithub  路  3Comments

Nitwel picture Nitwel  路  3Comments

Varulv1997 picture Varulv1997  路  3Comments

ondronix picture ondronix  路  3Comments

metalmarco picture metalmarco  路  3Comments