Skip to content

feat: expose a method to provide functional http interceptors without having to use withInterceptors([...]) #51303

@eneajaho

Description

@eneajaho

Which @angular/* package(s) are relevant/related to the feature request?

common

Description

When using class based interceptors we were able to just provide a token and it would be registered.

providers: [
  {
    provide: HTTP_INTERCEPTORS,
    useClass: ErrorsInterceptor,
    multi: true,
  }
]

This gave us the possibility to just provide this token and the DI would do it's job to register the interceptor.

With functional http interceptors, we loose this ability because we have to register them using the withInterceptor() method inside provideHttpClient() like this:

providers: [
  provideHttpClient(withInterceptors([errorInterceptor]))
]

This is great until we need to add providers or interceptors from a library. For example:

providers: [
  provideHttpCache()
]

I want to be able register some http interceptors from this provider function directly (just like we were able to do it before).

Proposed solution

Maybe expose HTTP_INTERECPTOR_FNS so we can just provide this token with our providers just like before.

Or expose a method that provides this token with our value.

Sth like:

provideInterceptors([errorInterceptor])

Alternatives considered

Use class based interceptors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions