Currently, the onRequest interceptor is called the following way:
await base.interceptors?.onRequest?.(targetUrl, { ...reqInit, url: targetUrl });
This means that the request initialization configuration is cloned, not passed directly. as a result, modifying the reqInit within the interceptor is a no-op, which takes away significant flexibility.
For example, I would like to be able to set some defaults for the init based on some state of my application, such as having credentials: true in certain scenarios. I have a lot of requests in my application, adding the credentials k-v pair to each would mean violating DRY heavily.
I think that onRequest should either return the new value for the reqInit (and undefined for no-op for backwards compatibility), or the reqInit should be passed by reference rather than by the spread operator (which risks introducing side-effects in existing code, so is less favorable).
I could PR this if others like the idea.
Currently, the onRequest interceptor is called the following way:
This means that the request initialization configuration is cloned, not passed directly. as a result, modifying the
reqInitwithin the interceptor is a no-op, which takes away significant flexibility.For example, I would like to be able to set some defaults for the
initbased on some state of my application, such as havingcredentials: truein certain scenarios. I have a lot of requests in my application, adding thecredentialsk-v pair to each would mean violating DRY heavily.I think that onRequest should either return the new value for the reqInit (and undefined for no-op for backwards compatibility), or the reqInit should be passed by reference rather than by the spread operator (which risks introducing side-effects in existing code, so is less favorable).
I could PR this if others like the idea.