API response compression

Abstract

Overview of API response compression along with an example of the default response compression configuration.

The Commerce Service API uses JSON responses. JSON responses are not natively compressed. Response compression can optimize network bandwidth usage and increase application responsiveness. The Commerce Engine supports JSON compression using GZIP, based the on Microsoft ASP.net Core 2.1., and using the Microsoft.AspNetCore.ResponseCompression package.

By default, API response compression is enabled at the fastest level, in all Commerce Engine environments (for example, CommerceAuthoring_Sc, CommerceMinions,_Sc, CommerceShops_Sc, and CommerceOps_Sc).

You can change API compression response configuration using the C:\inetpub\wwwroot\<CommerceEnvironment>\wwwroot\config.json file.

The following shows an example of the default response compression configuration:

 },
  "Compression": {
    "Enabled": true,
    "ResponseCompressionOptions": {
      "EnableForHttps": true,
      "MimeTypes": [
        "text/plain",
        "text/css",
        "application/javascript",
        "text/html",
        "application/xml",
        "text/xml",
        "application/json",
        "text/json",
        "application/wasm"      ]
    },
    "GzipCompressionProviderOptions": {
      "Level": "Fastest"
    }
  }

To disable response compression, for example, in the CommerceAuthoring_Sc9 environment:

  1. Open the C:\inetpub\wwwroot\CommerceAuthoring_Sc\wwwroot\config.json file.

  2. In the "Compression" section, set the following parameter: "Enabled":false.

  3. Save the file.

To change the compression level:

  1. Open the C:\inetpub\wwwroot\CommerceAuthoring_Sc\wwwroot\config.json file.

  2. Go to the "GzipCompressionProviderOptions" section, and set the "Level" to the desired value.

    Note

    The Commerce Engine supports the following ASP.net Core 2.1 standard compression levels: Fastest, Optimal , NoCompression. The default value is Fastest.

  3. Save the file.