Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: fetch based adapter #1219

Closed
ccnokes opened this issue Dec 4, 2017 · 47 comments
Closed

Feature request: fetch based adapter #1219

ccnokes opened this issue Dec 4, 2017 · 47 comments
Assignees
Labels
Projects

Comments

@ccnokes
Copy link

ccnokes commented Dec 4, 2017

I didn't see an issue for this (opened or closed), but if this is a duplicate just close it 😸 .

Are there any plans for a fetch based adapter for axios? I thought I'd check and see if this has been discussed, and if not, if you all would be open to a feature request (or I'm happy to work on it and PR it).

Reasons for adding a fetch adapter are basically for the same reasons you'd use fetch:

  • Support for service workers
  • Integration with Cache API
  • natively promise based, so axios can become a thinner library
  • response streaming
  • probably more that I'm not even thinking of right now

Reasons you'd still want axios wrapping fetch for you (because some people feel like you don't need a lib over fetch):

  • fetch is low level. Using plain fetch in an app that is 99% GET/PUT/POST against a JSON API means lots of duplicate boilerplate code which axios can abstract
  • request/response interceptors
  • probably more that I'm not even thinking of right now 😄
@mividtim
Copy link

👍

@jc275
Copy link

jc275 commented Jan 1, 2018

Agreed. This looks like a dealbreaker for using Axios in PWAs, because the serviceworker can only intercept and cache http requests sent via the fetch api.

Discussed in #484

@jabacchetta
Copy link

Just noticed this after diving into service workers this week. Is isomorphic-fetch a viable alternative for PWAs?

@ccnokes
Copy link
Author

ccnokes commented Jan 9, 2018

@jabacchetta I have no experience with PWAs yet but I would think so. If you want something sort of axios like, https://github.com/jackfranklin/so-fetch, looks good (haven't tried it yet personally though).

@jabacchetta
Copy link

Great, thanks! I'll take a look.

@NShahri
Copy link

NShahri commented Jan 11, 2018

Is there any implementation for 'fetch adapter' in progress? otherwise I can work on it

@ccnokes
Copy link
Author

ccnokes commented Jan 13, 2018

@NShahri I haven't started on anything yet, sadly ☹️

@NShahri
Copy link

NShahri commented Jan 14, 2018

@ccnokes Ok, I will send pull request soon

@ccnokes
Copy link
Author

ccnokes commented Jan 16, 2018

I actually just started working on this too (don't let this discourage you @NShahri, yours might be better or I might not finish it, etc).

Still hoping for some positive signal from a maintainer. @nickuraltsev or @mzabriskie any thoughts on this?

I haven't gotten too far into the implementation yet but I know one question that'll come up is do you explicitly opt into the fetch adapter or does it take precedence over the XMLHttpRequest one, if available? I'm sure more questions will come later 😄.

@NShahri
Copy link

NShahri commented Jan 16, 2018

@ccnokes, at the moment I change the code to choose fetch adapter when fetch is available otherwise it will choose XHR adapter.

Also I am using whatwg-fetch polyfill in test environment as it lets me to run the all current tests against fetch adapter with minimum changes. This polyfill uses XHR to implement fetch, so I can use it on test environment for running current XHR tests for fetch adapter. But I am no sure about this approach.

In addition I have another question about 'withCredentials' as I think it can be mapped to request.credentials which can accept 'include', 'omit' and 'same-origin' as value. I am not sure 'include' or 'same-origin' is the right value when withCredianls=true or should I change axios interface to let user to choose value except true or false.

@nickuraltsev @mzabriskie

I am working on 22 failed test to finalise the implementation and send pull request.

@NShahri
Copy link

NShahri commented Jan 16, 2018

@ccnokes this is my first try to implement fetch adapter https://github.com/axios/axios/compare/master...NShahri:feature/fetch-adapter?w=1

Remaining tasks:

  • Progress handlers (download and upload)
  • Setting timeout: When AbortController is supported by browser or polyfill
  • Check new timeout test: It is failing on xhr adapter
  • Abort: When AbortController is supported by browser or polyfill
  • Redirects
  • Use new implemented utils/enums in http and xhr adapter
  • Test bundle size
  • Passing all tests using polyfill
  • finalise tests for fetch
  • run tests for all xhr, http and fetch adapters

@ccnokes
Copy link
Author

ccnokes commented Jan 17, 2018

Nice @NShahri! Let me know if you need help with anything.

@NShahri
Copy link

NShahri commented Jan 17, 2018

Thanks @ccnokes, Feel free to start implementing any of remaining tasks. let me know which one you started to avoid both of us working on the same task.

@ccnokes
Copy link
Author

ccnokes commented Jan 24, 2018

Hey @NShahri sorry for the delay, I'll take a look this week at the Redirects task.

How should we do this? Should I fork/PR you or do you want me just committing directly to your fork?

@NShahri
Copy link

NShahri commented Jan 31, 2018

@ccnokes sorry for delay.
it is up to you fork/PR me or direct commiting

@eybarta
Copy link

eybarta commented Apr 18, 2018

Hey guys, any progress on this? I would LOVE to keep using axios, but I need to implement
offline availability with SW's, can I do anything to help?

thx

@NShahri
Copy link

NShahri commented Apr 18, 2018

@eybarta
Unfortunately I am too busy and can not finalise this feature.

The minimum requirements are implemented and tested, but I haven't use this in any app. It would be great if you have time and use it in your app. https://github.com/NShahri/axios/tree/feature/fetch-adapter

There is a list of remaining tasks in #1219 (comment).

NOTE:

  • there are some missing functionalities because it is not supported by fetch in some browsers like request timeout and progress handler
  • because of the differences between xhr and fetch, there are some functionality in fetch which is not implemented by axios, like credentials: 'same-origin'

Next phase to finalise fetch adapter would be changing axios interface to accept options which user can use to configure fetch request

@rajatvijay
Copy link

@NShahri

are all the remaining task done and released?
If not is it up for grabs?

@ccnokes
Copy link
Author

ccnokes commented Nov 14, 2018

Personally, I'd be wary of working on adding fetch support as a PR, especially as there hasn't been any interest shown from maintainers. Also I noticed there's a 1.0.0 version in the plans: https://github.com/axios/axios/projects/2. Maybe a fetch adapter will be a part of that?

@Mechazawa
Copy link

It'd be great if a fetch adapter can be part of 1.0.0. It'd solve a lot of issues I have with xhrAdapter.

@juanarbol
Copy link

@ccnokes This issue is already solved, close please.

@Mechazawa
Copy link

Mechazawa commented Jan 9, 2019

@juanarbol What PR was it fixed in? I can't find the fetch adapter in the codebase.

@juanarbol
Copy link

My bad, if anyone could explain me how to solve, I could help

@cristianoccazinsp
Copy link

Any news on this? When using react native, fetch seems to be way faster than xhr to process json responses and it would be great to use a fetch adapter.

@pchaganti
Copy link

👍

sgammon added a commit to sgammon/axios-fetch that referenced this issue Oct 17, 2022
This changeset adds a `fetch`-based adapter implementation to
`axios`, powered by `cross-fetch`[1]. The implementation may thus
be used on either Node or in browser environments.

Changes enclosed:
- Add `fetch` adapter implementation
- Add `fetch` to standard built-in adapters
- Add initial Node-side tests for `fetch`
- Slight refactor to tests to use common setup / teardown code

Still pending:
- Upload/download progress events
- Browser-side testing

Fixes and closes axios#1219, and supersedes axios#2891.
@mh-alahdadian
Copy link

As far as I know we can not have a upload progress percentage with fetch base technology , Are you going to implement a adapter without supporting upload progress feature ?

@sgammon
Copy link

sgammon commented Oct 18, 2022

@mh-alahdadian i haven't gotten that far yet. streams aren't yet standardized on the web platform but perhaps there is a high-quality polyfill or workaround.

in any case, i don't see why this would be a practical limitation. if you're in a browser environment, you can still use the XHR adapter, which supports the progress event (axios supports download and upload progress on top of XHR).

if you're in a node environment, you can use the http adapter, which also supports upload and download progress.

in more exotic environments like CloudFlare Workers, where you only have access to fetch, this may be an unsupported feature until the spec lands, only because the runtime may not emit the requisite events.

EDIT: @mh-alahdadian looks like ReadableStream is at 95% on caniuse and has high-quality polyfills, so i'll wire that in for the upload/download events in browser environments, if that's relevant to your needs. the upload side of it is still rather fresh in Chrome, so if it is even possible to land upload events in the browser, it will probably be hidden behind a flag.

@KaKi87
Copy link

KaKi87 commented Oct 26, 2022

One more reason in favor of a fetch adapter is Deno support.

Thanks

sgammon added a commit to sgammon/axios-fetch that referenced this issue Nov 14, 2022
This changeset adds a `fetch`-based adapter implementation to
`axios`, powered by `cross-fetch`[1]. The implementation may thus
be used on either Node or in browser environments.

Changes enclosed:
- Add `fetch` adapter implementation
- Add `fetch` to standard built-in adapters
- Add initial Node-side tests for `fetch`
- Slight refactor to tests to use common setup / teardown code

Still pending:
- Upload/download progress events
- Browser-side testing

Fixes and closes axios#1219, and supersedes axios#2891.
sgammon added a commit to sgammon/axios-fetch that referenced this issue Dec 17, 2022
This changeset adds a `fetch`-based adapter implementation to
`axios`, powered by `cross-fetch`[1]. The implementation may thus
be used on either Node or in browser environments.

Changes enclosed:
- Add `fetch` adapter implementation
- Add `fetch` to standard built-in adapters
- Add initial Node-side tests for `fetch`
- Slight refactor to tests to use common setup / teardown code

Still pending:
- Upload/download progress events
- Browser-side testing

Fixes and closes axios#1219, and supersedes axios#2891.
sgammon added a commit to sgammon/axios-fetch that referenced this issue Dec 18, 2022
This changeset adds a `fetch`-based adapter implementation to
`axios`, powered by `cross-fetch`[1]. The implementation may thus
be used on either Node or in browser environments.

Changes enclosed:
- Add `fetch` adapter implementation
- Add `fetch` to standard built-in adapters
- Add initial Node-side tests for `fetch`
- Slight refactor to tests to use common setup / teardown code

Still pending:
- Upload/download progress events
- Browser-side testing

Fixes and closes axios#1219, and supersedes axios#2891.
sgammon added a commit to sgammon/axios-fetch that referenced this issue Dec 19, 2022
This changeset adds a `fetch`-based adapter implementation to
`axios`, powered by `cross-fetch`[1]. The implementation may thus
be used on either Node or in browser environments.

Changes enclosed:
- Add `fetch` adapter implementation
- Add `fetch` to standard built-in adapters
- Add initial Node-side tests for `fetch`
- Slight refactor to tests to use common setup / teardown code

Still pending:
- Upload/download progress events
- Browser-side testing

Fixes and closes axios#1219, and supersedes axios#2891.
sgammon added a commit to sgammon/axios-fetch that referenced this issue Sep 14, 2023
This changeset adds a `fetch`-based adapter implementation to
`axios`, powered by `cross-fetch`[1]. The implementation may thus
be used on either Node or in browser environments.

Changes enclosed:
- Add `fetch` adapter implementation
- Add `fetch` to standard built-in adapters
- Add initial Node-side tests for `fetch`
- Slight refactor to tests to use common setup / teardown code

Still pending:
- Upload/download progress events
- Browser-side testing

Fixes and closes axios#1219, and supersedes axios#2891.
@TaxBusby
Copy link

TaxBusby commented Feb 9, 2024

Another new JS runtime, llrt just came out, boasting low latency startups for serverless environments. It supports fetch but not http.request. So a fetch adapter would help support this runtime as well.

@KaKi87
Copy link

KaKi87 commented Feb 9, 2024

For now I recommend @haverstack/axios-fetch-adapter.

@sgammon
Copy link

sgammon commented Feb 10, 2024

cc / @jasonsaayman I'd still love to join discord and attack this; let me know if that's welcome at all :)

sgammon added a commit to sgammon/axios-fetch that referenced this issue Apr 11, 2024
This changeset adds a `fetch`-based adapter implementation to
`axios`, powered by `cross-fetch`[1]. The implementation may thus
be used on either Node or in browser environments.

Changes enclosed:
- Add `fetch` adapter implementation
- Add `fetch` to standard built-in adapters
- Add initial Node-side tests for `fetch`
- Slight refactor to tests to use common setup / teardown code

Still pending:
- Upload/download progress events
- Browser-side testing

Fixes and closes axios#1219, and supersedes axios#2891.
@DigitalBrainJS
Copy link
Collaborator

Fetch adapter was added in v1.7.0-beta.0
Use npm i axios@next to install the beta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
v1.0.0
  
To do