Newer Version Available

This content describes an older version of this product. View Latest

Compression Headers

Use a compression header to compress a REST API request or response. Compression reduces the bandwidth required for a request, although it requires more processing power at your client. In most cases, this tradeoff benefits the overall performance of your application.

REST API supports the gzip and deflate compression algorithms, as defined by the HTTP 1.1 specification. If you’re unsure about which one to use, gzip is more common than deflate.

For better performance, we suggest that clients accept and support compression as defined by the HTTP 1.1 specification.

Tip

Request Compression

Include a Content-Encoding: gzip or Content-Encoding: deflate header to compress a request. REST API decompresses any requests before processing.

This example request is compressed with gzip.

1curl https://MyDomainName.my.salesforce.com/services/data/v55.0/sobjects/Account/ -H "Authorization: Bearer access-token" -H "Content-Type: application/json" -H "Content-Encoding: gzip" —data-binary @new-account.json -X POST

Response Compression

Salesforce compresses a response only if the request contains an Accept-Encoding: gzip or Accept-Encoding: deflate header. REST API isn’t required to compress the response even if you’ve specified Accept-Encoding, but it normally does. If compressed, the response contains a Content-Encoding header with the compression algorithm so that your client knows to decompress it.

This example request asks for a compressed response.

1curl https://MyDomainName.my.salesforce.com/services/data/v55.0/sobjects/Account/0015e000009sS0DAAU -H "Authorization: Bearer access-token" -H "Content-Type: application/json" -H "Accept-Encoding: gzip" -X GET