Toolbelt.Blazor.HttpClientInterceptor 6.1.0

Intercept all of the sending HTTP requests on a client side Blazor application.

This package is considered a SemVer 2.0.0 package as it has a package dependency on SemVer 2.0.0 package(s).
This package will only be available to download with SemVer 2.0.0 compatible NuGet clients, such as Visual Studio 2017 (version 15.3) and above or NuGet client 4.3.0 and above. Read more
Install-Package Toolbelt.Blazor.HttpClientInterceptor -Version 6.1.0
dotnet add package Toolbelt.Blazor.HttpClientInterceptor --version 6.1.0
<PackageReference Include="Toolbelt.Blazor.HttpClientInterceptor" Version="6.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Toolbelt.Blazor.HttpClientInterceptor --version 6.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Blazor WebAssembly (client-side) HttpClient Interceptor NuGet Package

Summary

The class library that intercept all of the sending HTTP requests on a client side Blazor WebAssembly application.

Supported Blazor versions

"Blazor WebAssembly App (client-side) HttpClient Interceptor" ver.6.x supports Blazor WebAssembly App version 3.1 Preview 3, and 4.

How to install and use?

Step.1 Install the library via NuGet package, like this.

>  dotnet add package Toolbelt.Blazor.HttpClientInterceptor

Step.2 Register "HttpClientInterceptor" service into the DI container, at ConfigureService method in the Startup class of your Blazor application.

using Toolbelt.Blazor.Extensions.DependencyInjection; // <- Add this, and...
...
public class Startup
{
  public void ConfigureServices(IServiceCollection services)
  {
    services.AddHttpClientInterceptor(); // <- Add this line.
    ...

That's all.

You can subscribe the events that will occur before/after sending all of the HTTP requests, at anywhere you can get HttpClientInterceptor service from the DI container.

@using Toolbelt.Blazor
@inject HttpClientInterceptor Interceptor
...
@code {
  protected override void OnInitialized()
  {
    this.Interceptor.BeforeSend += Interceptor_BeforeSend;
    ...
  }

  void Interceptor_BeforeSend(object sender, HttpClientInterceptorEventArgs e)
  {
    // Do something here what you want to do.
  }
  ...

Note: Please remember that if you use HttpClientInterceptor to subscribe BeforeSend/AfterSend events in Blazor components (.razor), you should unsubscribe events when the components is discarded. To do it, you should implement IDisposable interface in that component, like this code:

@implements IDisposable
...
public void Dispose()
{
  this.Interceptor.BeforeSend -= Interceptor_BeforeSend;
}

The arguments of event handler

The event handler for BeforeSend/AfterSend events can be received HttpClientInterceptorEventArgs object.

The HttpClientInterceptorEventArgs object provides you to a request object and a response object that is come from an intercepted HttpClinet request.

void OnAfterSend(object sender, HttpClientInterceptorEventArgs args)
{
  if (!args.Response?.IsSuccessStatusCode) {
    // Do somthing here for handle all errors of HttpClient requests.
  }
}

Release Note

  • v.6.1.0 - The event handler arguments now provides a request object and a response object.
  • v.6.0.0 - BREAKING CHANGE: Support Blazor v.3.1.0 Preview 3 (not compatible with v.3.1.0 Preview 2 or before.)
  • v.5.0.0 - BREAKING CHANGE: Support Blazor v.3.0.0 Preview 6 (not compatible with v.3.0.0 Preview 5 or before.)
  • v.4.0.0 - BREAKING CHANGE: Support Blazor v.3.0.0 Preview 4 (not compatible with v.0.9.0 or before.)
  • v.3.0.0 - BREAKING CHANGE: Support Blazor v.0.8.0 (not compatible with v.0.7.0 or before.)
  • v.2.1.0 - Support Blazor v.0.6.0 - it was signed strong name.
  • v.2.0.0 - BREAKING CHANGE: Fix namespace of HttpClientInterceptorExtension class.
  • v.1.0.0 - 1st release.

License

Mozilla Public License Version 2.0

Blazor WebAssembly (client-side) HttpClient Interceptor NuGet Package

Summary

The class library that intercept all of the sending HTTP requests on a client side Blazor WebAssembly application.

Supported Blazor versions

"Blazor WebAssembly App (client-side) HttpClient Interceptor" ver.6.x supports Blazor WebAssembly App version 3.1 Preview 3, and 4.

How to install and use?

Step.1 Install the library via NuGet package, like this.

>  dotnet add package Toolbelt.Blazor.HttpClientInterceptor

Step.2 Register "HttpClientInterceptor" service into the DI container, at ConfigureService method in the Startup class of your Blazor application.

using Toolbelt.Blazor.Extensions.DependencyInjection; // <- Add this, and...
...
public class Startup
{
  public void ConfigureServices(IServiceCollection services)
  {
    services.AddHttpClientInterceptor(); // <- Add this line.
    ...

That's all.

You can subscribe the events that will occur before/after sending all of the HTTP requests, at anywhere you can get HttpClientInterceptor service from the DI container.

@using Toolbelt.Blazor
@inject HttpClientInterceptor Interceptor
...
@code {
  protected override void OnInitialized()
  {
    this.Interceptor.BeforeSend += Interceptor_BeforeSend;
    ...
  }

  void Interceptor_BeforeSend(object sender, HttpClientInterceptorEventArgs e)
  {
    // Do something here what you want to do.
  }
  ...

Note: Please remember that if you use HttpClientInterceptor to subscribe BeforeSend/AfterSend events in Blazor components (.razor), you should unsubscribe events when the components is discarded. To do it, you should implement IDisposable interface in that component, like this code:

@implements IDisposable
...
public void Dispose()
{
  this.Interceptor.BeforeSend -= Interceptor_BeforeSend;
}

The arguments of event handler

The event handler for BeforeSend/AfterSend events can be received HttpClientInterceptorEventArgs object.

The HttpClientInterceptorEventArgs object provides you to a request object and a response object that is come from an intercepted HttpClinet request.

void OnAfterSend(object sender, HttpClientInterceptorEventArgs args)
{
  if (!args.Response?.IsSuccessStatusCode) {
    // Do somthing here for handle all errors of HttpClient requests.
  }
}

Release Note

  • v.6.1.0 - The event handler arguments now provides a request object and a response object.
  • v.6.0.0 - BREAKING CHANGE: Support Blazor v.3.1.0 Preview 3 (not compatible with v.3.1.0 Preview 2 or before.)
  • v.5.0.0 - BREAKING CHANGE: Support Blazor v.3.0.0 Preview 6 (not compatible with v.3.0.0 Preview 5 or before.)
  • v.4.0.0 - BREAKING CHANGE: Support Blazor v.3.0.0 Preview 4 (not compatible with v.0.9.0 or before.)
  • v.3.0.0 - BREAKING CHANGE: Support Blazor v.0.8.0 (not compatible with v.0.7.0 or before.)
  • v.2.1.0 - Support Blazor v.0.6.0 - it was signed strong name.
  • v.2.0.0 - BREAKING CHANGE: Fix namespace of HttpClientInterceptorExtension class.
  • v.1.0.0 - 1st release.

License

Mozilla Public License Version 2.0

Release Notes

v.6.1.0
- The event handler arguments now provides a request object and a response object.
v.6.0.0
- BREAKING CHANGE: Support Blazor v.3.1.0 Preview 3 (not compatible with v.3.1.0 Preview 2 or before.)
v.5.0.0
- BREAKING CHANGE: Support Blazor v.3.0.0 Preview 6 (not compatible with v.3.0.0 Preview 5 or before.)
v.4.0.0
- BREAKING CHANGE: Support Blazor v.3.0.0 Preview 4 (not compatible with v.0.9.0 or before.)
v.3.0.0
- BREAKING CHANGE: Support Blazor v.0.8.0 (not compatible with v.0.7.0 or before.)
v.2.1.0
- Support Blazor v.0.6.0 - it was signed strong name.
v.2.0.0
- BREAKING CHANGE: Fix namespace of HttpClientInterceptorExtension class.
v.1.0.0
- 1st release.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
6.1.0 0 1/24/2020
6.0.0 1,844 11/20/2019
5.0.0 2,684 6/14/2019
4.0.0.3 251 4/26/2019
3.0.0 217 2/8/2019
2.1.0 791 10/3/2018
2.0.0 163 9/21/2018
1.0.0 172 9/14/2018