tus-js-client icon indicating copy to clipboard operation
tus-js-client copied to clipboard

Add an HttpStack for Axios

Open SpecLad opened this issue 2 years ago • 7 comments

Is your feature request related to a problem? Please describe. In our project we mostly use Axios for making HTTP queries, with some default settings configured globally (e.g. default HTTP headers). We also use tus-js-client, but since it uses its own HTTP stack, we have to replicate the default Axios settings into their tus-js-client equivalents. This causes code duplication, and it's easy to forget to replicate a setting, which leads to divergent behavior.

Describe the solution you'd like It would be nice if I could write something like this and have tus-js-client work through Axios:

import Axios from 'axios';

const upload = new tus.Upload(file, { httpStack: tus.AxiosHttpStack(Axios), ... });

// or
const axiosInstance = Axios.create({ ... });
const upload = new tus.Upload(file, { httpStack: tus.AxiosHttpStack(axiosInstance ), ... });

That way, all Axios settings would automatically be applied.

Describe alternatives you've considered I'm aware that I could just implement this AxiosHttpStack on my side. However, Axios is a popular library, so I think many users could find this useful if it was included in tus-js-client.

Can you provide help with implementing this feature? In principle, yes, although I don't know when I'll be able to get around to it.

Additional context N/A

SpecLad avatar Mar 29 '23 10:03 SpecLad

What config settings in Axios could be set that way? From https://axios-http.com/docs/config_defaults, I feel like only a base URL and headers can be configured.

In general, I do see a use for this, but don't think we will have time ourselves to work on this. So if anybody else is interested, we are happy to assist.

Acconut avatar Mar 31 '23 01:03 Acconut

Ok, then let's see if somebody wants to tackle this.

Acconut avatar Mar 31 '23 11:03 Acconut

Hello, @Acconut. I would love to take this issue and work on it.

ArunBohra12 avatar Jun 24 '23 15:06 ArunBohra12

That's great to hear! Let me know if you need some help getting started. It should be as simple as copying https://github.com/tus/tus-js-client/blob/main/lib/browser/httpStack.js and replacing XMLHttpRequest with Axios.

Acconut avatar Jun 27 '23 10:06 Acconut