DEV Community

Cesar Aguirre
Cesar Aguirre

Posted on • Originally published at canro91.github.io

How to add gzip compression to ASP.NET Core API responses

If you're using ASP.NET Core 2.x, you need to install the NuGet Microsoft.AspNetCore.ResponseCompression

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<GzipCompressionProviderOptions>(options => 
    {
        options.Level = CompressionLevel.Fastest;
    });
    services.AddResponseCompression(options =>
    {
        options.Providers.Add<GzipCompressionProvider>();
    });
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseResponseCompression();
}
Enter fullscreen mode Exit fullscreen mode

Source: Response compression in ASP.NET Core

Top comments (0)