js-sdk icon indicating copy to clipboard operation
js-sdk copied to clipboard

Replace axios

Open rhamzeh opened this issue 2 years ago • 7 comments

Summary

axios v1 has brought a few breaking changes, so now's the time to reconsider whether it still is the best solution we have.

Motivation(s)

  • http2/http3 support
  • streaming support
  • reduce dependencies

Downsides

  • Breaking change - axios is very tied to our responses, anyone who currently depends on them will have some work to do before they can upgrade

Alternatives to consider

  • axios: it's working, stick to it, but update to a v1.x.x+ version (no http2 support yet)
  • fetch: built into recent browsers and node 18+
  • gaxios: close to the axios interface, supports http2, no browser support
  • got: Seems to satisfy a lot constraints. No browser support and has a lot of dependencies
  • ky: tiny, no dependencies, supports deno
  • undici: from the core node devs, no browser support but much better performance
  • ...

Criteria for success

  • Compatible license (required)
  • Node.js 18+ support (required)
  • Brings in a minimal set of dependencies (required)
  • Promise based (required)
  • Streaming support: allows us to expose the streaming ListObjects
  • http2/http3 support: reduces request overhead
  • Deno support (https://github.com/openfga/js-sdk/issues/17)
  • Cloudflare Worker and Vercel support (https://github.com/openfga/js-sdk/issues/72)
  • Better support for proxies (https://github.com/orgs/openfga/discussions/310)
  • Browser support: needed for the Playground
  • Preferably not another dependency (bonus)
  • Error handling and automated retries (bonus - lets us drop our own implementation)
  • Credential flow support (bonus - lets us drop our own implementation)
  • Built-in caching support (bonus)

State (as of June 2024)

We're currently favouring undici and planning on starting work on this soon

rhamzeh avatar May 22 '23 12:05 rhamzeh

I can definitely recommend ky. It's fetch with an excellent interface.

RichiCoder1 avatar May 29 '23 22:05 RichiCoder1

The replacement should also support Cloudflare Workers like environments (https://github.com/openfga/js-sdk/issues/72)

ntotten avatar May 29 '24 21:05 ntotten

Hi, Considering support for http corporate proxy with self signed certificate maybe ? ( see https://github.com/orgs/openfga/discussions/310 )

nicoduj avatar May 30 '24 14:05 nicoduj

Just as an FYI - we are planning on starting work on this within the next two months.

We are leaning heavily towards undici, mostly for performance & current maintenance reasons. Ensuring compatibility w/ fetch in environments where undici is not available (Cloudflare Workers, Vercel, Browser, etc..) is part of this work

rhamzeh avatar May 30 '24 16:05 rhamzeh

I think got would be a great alternative, though I think anything but axios would be fine

gitaugakwa avatar May 31 '24 17:05 gitaugakwa