stateful fetch client
Describe the feature
ofetch/$fetch same as native fetch is stateless by-design. This has safety advantages when ofetch is deeply integrated into tools such as Nitro and Nuxt and prevents global side effects and potential header leaks.
However, there are also good use cases of having stateful fetch instances:
- Sharable headers
- Cookie jar (#382)
- Global interceptors such as auth
I think $fetch.withState() could be useful.
It's very good idea especially useful for testing API's
Hi @pi0
What's the difference between this and ofetch.create ?
@guyaumetremblay ofetch.create creates instance with immutable defaults. this version has mutable state (and most importantly working cookies, just like a browser tab)
Here from #456 and honestly would really love to have some way to merge interceptors instead of overriding them