-
Notifications
You must be signed in to change notification settings - Fork 297
Description
Data API builder does not currently support response compression (e.g., gzip or brotli), which can significantly reduce payload size and improve performance over slow or high-latency networks. Compression is especially beneficial for large JSON responses, common in REST and GraphQL endpoints. Adding support at the server level—either via built-in middleware or integration guidance—would help DAB serve clients more efficiently. This is a common feature in modern web APIs and would be a strong addition to the roadmap.
Sample request
GET /api/employees HTTP/1.1
Host: api.example.com
Accept-Encoding: gzip, deflate, br
Sample response
HTTP/1.1 200 OK
Content-Encoding: gzip
Content-Type: application/json
Content-Length: 920
Payload impact
| Payload Type | Uncompressed (bytes) | Gzipped (bytes) | Compression Savings |
|---|---|---|---|
| Large JSON array | 4,356 | 920 | ~79% |
Configuration Update
{
"runtime": {
"compression": {
"level": "fastest" | "optimal" | "none" <default: optimal>
}
}
}CLI update
dab configure --runtime.compression.level fastest
Starter JSON Schema section
{
"runtime": {
"type": "object",
"properties": {
"compression": {
"type": "object",
"description": "Configures HTTP response compression settings.",
"properties": {
"level": {
"type": "string",
"enum": ["fastest", "optimal", "none"],
"default": "optimal",
"description": "Specifies the response compression level."
}
},
"additionalProperties": false
}
}
}
}Basic ASPNET implementation
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddResponseCompression(options =>
{
options.EnableForHttps = true;
options.Providers.Add<GzipCompressionProvider>();
});
builder.Services.Configure<GzipCompressionProviderOptions>(options =>
{
options.Level = CompressionLevel.Fastest;
});
var app = builder.Build();
app.UseResponseCompression();
// map endpoints and controllers
app.Run();FAQ
-
Is this backwards compatible?
Yes. Clients that don’t request compression (viaAccept-Encoding) receive uncompressed responses exactly as before. -
Does this require a special client?
No. Most modern browsers and HTTP clients (like curl, Postman, fetch, axios) already support compressed responses out-of-the-box. -
Does this impact controller logic?
No. Compression is handled at the middleware level, completely separate from your controller logic or data access code. -
What is the compute cost compared to bandwidth savings?
Compression uses CPU but reduces payload size dramatically. In most APIs, the tradeoff favors compression—especially for large or repetitive JSON responses. TheCompressionLevel.Fastestoption balances speed and size. -
Does this work over HTTPS?
Yes. Response compression is fully supported over HTTPS and can be explicitly enabled withEnableForHttps = true. -
Can it be customized for specific MIME types?
Yes. You can add custom MIME types (e.g.,application/graphql+json) if needed. -
What compression formats are supported?
Gzip is most common, but Brotli and Deflate are also supported in ASP.NET Core with the appropriate providers. -
Does it work with REST and GraphQL?
Yes. Compression applies to all HTTP responses regardless of the endpoint type, including both REST and GraphQL APIs. -
Does Hot Chocolate support it?
Hot Chocolate runs on ASP.NET Core and inherits its middleware pipeline, so response compression works with it automatically—no special configuration needed in Hot Chocolate itself.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status