Skip to content

Allow onRequest interceptors to modify the init config of the request #6

Description

@omgaXD

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions