1

We have a ServiceStack 5.8.1 API running in Azure that uses EF Core to run queries against an Azure SQL database that is returning 500,000+ records. Calling the API methods returns a JSON representation of the data down to the client.

The front-end client also running in Azure is an Angular 7.x SPA which is doing HTTP client calls to the API and consuming the returned JSON response.

Is there a way in ServiceStack to enable response compression something like GZIP (not caching - as we want the most recent data on every request) that would send the JSON response back to the Angular client in a compressed format?

If that is possible then we could then look to de-compress the result in the Angular client (if that's possible) so to reduce the amount of data being transferred over the network.

Adrian Wright
  • 145
  • 2
  • 7
  • Please see [ServiceStack's compression docs](https://docs.servicestack.net/compression) – mythz Feb 28 '20 at 02:58

1 Answers1

1

Look at method ToOptimizedResultAsync.
There is also ToOptimizedResultUsingCache if you are wanting responses that were cached.

Also mentioned here Enable gzip/deflate compression

Example:

var response = new SomeViewModel
{
  Results = ....
}

return base.Request.ToOptimizedResultAsync(response);
richardb
  • 943
  • 1
  • 10
  • 27
  • 1
    Best to refer them to the [Compression docs](https://docs.servicestack.net/compression), the easiest way for this case is likely to use the `[CompressResponse]` attribute. – mythz Feb 28 '20 at 02:25