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

replace axios with fetch #1525

Open
1 of 7 tasks
jimmywarting opened this issue Aug 27, 2022 · 7 comments
Open
1 of 7 tasks

replace axios with fetch #1525

jimmywarting opened this issue Aug 27, 2022 · 7 comments
Labels
discussion M-T: An issue where more input is needed to reach a decision enhancement M-T: A feature request for new functionality pkg:web-api applies to `@slack/web-api`
Milestone

Comments

@jimmywarting
Copy link
Contributor

(Describe your issue and goal here)

Packages:

Select all that apply:

  • @slack/web-api
  • @slack/rtm-api
  • @slack/webhooks
  • @slack/oauth
  • @slack/socket-mode
  • @slack/types
  • I don't know

Requirements

could you replace axios with fetch instead?

And preferable don't depend on any FormData, Blob, XHR, fetch dependency? let users bring there own instances instead b/c they exist globally in NodeJS now and if they need they can polyfill this stuff by themself. using undici, node-fetch or anything else

@seratch seratch added enhancement M-T: A feature request for new functionality discussion M-T: An issue where more input is needed to reach a decision pkg:web-api applies to `@slack/web-api` and removed untriaged labels Aug 29, 2022
@seratch seratch added this to the web-api@6.x milestone Aug 29, 2022
@seratch
Copy link
Member

seratch commented Aug 29, 2022

Hi @jimmywarting, thanks for the suggestion!

Although are not planning to work on the replacement in the short term (due to our priorities right now), I agree that we can make the API client package simpler in the interest of broader use cases in the future.

@maxcountryman
Copy link

It would be great if this were structured in such a way so that it could then work with runtimes that don't support Node, e.g. Cloudflare Workers/V8 isolates.

@jimmywarting
Copy link
Contributor Author

jimmywarting commented Aug 30, 2022

often when i code things then i have this mindset of coding things in a more cross env friendlier way and i'm also following this guidelines: https://github.com/cross-js/cross-js

The most fundamentals is to think of your application as an "onion" architecture that has different layers of supports.
at the very core of your application you shouldn't assume that you have access to any NodeJS, Deno, or any browser API's.
it shouldn't even assume that it has system IO (network, disc) access. Your internet may be down (offline) perhaps you may want to cache things or mock some data or configure the request/response before it's sent & received. maybe you want to listen to navigator.onLine and re-send the request once it's back up again. or simply just being able to debug outgoing requests for time measurement and progress listening

// Just one idea:
new WebClient({
  /**
   * - This option is required if you do not have globalThis.fetch or `globalThis.Response` 
   * - Omitting this option makes it so slack call `fetch()` for you.
   *
   * Same arguments you would use for making a `new Request(url, requestInit)`
   * the config.headers is either a 2D array or an object instead of a `Headers` class
   * 
   * @param {string} url
   * @param {RequestInit} config
   */
  onfetch (url, config) {
    config.signal = signal // add your own abort signal
    config.agent = agent // useful in NodeJS only
    // check if it exist in localStorage and if so return a new Response() manually
    return fetch(url, config)
  }
})

this way the developer can use whatever they already might have as an dependency , they might already depend on some node-fetch, got, axios, request or undici version, so you would then also avoid some duplicate code

@jimmywarting
Copy link
Contributor Author

it would also be grate if you could change buffer for uint8array instead.

@filmaj
Copy link
Contributor

filmaj commented Aug 30, 2022

I agree this is a great suggestion, as the use of axios makes this package less portable (to other runtimes like Deno, among other use cases). However, axios provides many different configuration options, like proxy support, which, if I understand correctly, is an important option used by many Slack application developers today (particularly in corporate environments).

So whatever replacement would be adequate, I just wanted to explicitly point out the need to maintain some amount of backwards compatibility for these secondary features like proxy support.

@alexbjorlig
Copy link

And security 🧐

Snyk just posted this CSRF issue with Axios.

@filmaj
Copy link
Contributor

filmaj commented Oct 25, 2023

Worth revisiting this issue as I am inching towards a new major release of web-api (with things like better type safety of API arguments). In the next release, web-api will require node v18 minimum.

I wonder if in node 18+ it is easier to implement some of the more corporate-y features web-api provides like proxies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion M-T: An issue where more input is needed to reach a decision enhancement M-T: A feature request for new functionality pkg:web-api applies to `@slack/web-api`
Projects
None yet
Development

No branches or pull requests

5 participants