# Variants ## Get variants setting `client.Cache.Variants.Get(ctx, query) (*VariantGetResponse, error)` **get** `/zones/{zone_id}/cache/variants` Variant support enables caching variants of images with certain file extensions in addition to the original. This only applies when the origin server sends the 'Vary: Accept' response header. If the origin server sends 'Vary: Accept' but does not serve the variant requested, the response will not be cached. This will be indicated with BYPASS cache status in the response headers. ### Parameters - `query VariantGetParams` - `ZoneID param.Field[string]` Identifier. ### Returns - `type VariantGetResponse struct{…}` - `ID VariantGetResponseID` The identifier of the caching setting. - `const VariantGetResponseIDVariants VariantGetResponseID = "variants"` - `Editable bool` Whether the setting is editable. - `Value VariantGetResponseValue` Value of the zone setting. - `AVIF []string` List of strings with the MIME types of all the variants that should be served for avif. - `BMP []string` List of strings with the MIME types of all the variants that should be served for bmp. - `GIF []string` List of strings with the MIME types of all the variants that should be served for gif. - `JP2 []string` List of strings with the MIME types of all the variants that should be served for jp2. - `JPEG []string` List of strings with the MIME types of all the variants that should be served for jpeg. - `JPG []string` List of strings with the MIME types of all the variants that should be served for jpg. - `JPG2 []string` List of strings with the MIME types of all the variants that should be served for jpg2. - `PNG []string` List of strings with the MIME types of all the variants that should be served for png. - `TIF []string` List of strings with the MIME types of all the variants that should be served for tif. - `TIFF []string` List of strings with the MIME types of all the variants that should be served for tiff. - `WebP []string` List of strings with the MIME types of all the variants that should be served for webp. - `ModifiedOn Time` Last time this setting was modified. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/cache" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) variant, err := client.Cache.Variants.Get(context.TODO(), cache.VariantGetParams{ ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", variant.ID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "id": "variants", "editable": true, "value": { "avif": [ "image/webp", "image/jpeg" ], "bmp": [ "image/webp", "image/jpeg" ], "gif": [ "image/webp", "image/jpeg" ], "jp2": [ "image/webp", "image/avif" ], "jpeg": [ "image/webp", "image/avif" ], "jpg": [ "image/webp", "image/avif" ], "jpg2": [ "image/webp", "image/avif" ], "png": [ "image/webp", "image/avif" ], "tif": [ "image/webp", "image/avif" ], "tiff": [ "image/webp", "image/avif" ], "webp": [ "image/jpeg", "image/avif" ] }, "modified_on": "2014-01-01T05:20:00.12345Z" } } ``` ## Change variants setting `client.Cache.Variants.Edit(ctx, params) (*VariantEditResponse, error)` **patch** `/zones/{zone_id}/cache/variants` Variant support enables caching variants of images with certain file extensions in addition to the original. This only applies when the origin server sends the 'Vary: Accept' response header. If the origin server sends 'Vary: Accept' but does not serve the variant requested, the response will not be cached. This will be indicated with BYPASS cache status in the response headers. ### Parameters - `params VariantEditParams` - `ZoneID param.Field[string]` Path param: Identifier. - `Value param.Field[VariantEditParamsValue]` Body param: Value of the zone setting. - `AVIF []string` List of strings with the MIME types of all the variants that should be served for avif. - `BMP []string` List of strings with the MIME types of all the variants that should be served for bmp. - `GIF []string` List of strings with the MIME types of all the variants that should be served for gif. - `JP2 []string` List of strings with the MIME types of all the variants that should be served for jp2. - `JPEG []string` List of strings with the MIME types of all the variants that should be served for jpeg. - `JPG []string` List of strings with the MIME types of all the variants that should be served for jpg. - `JPG2 []string` List of strings with the MIME types of all the variants that should be served for jpg2. - `PNG []string` List of strings with the MIME types of all the variants that should be served for png. - `TIF []string` List of strings with the MIME types of all the variants that should be served for tif. - `TIFF []string` List of strings with the MIME types of all the variants that should be served for tiff. - `WebP []string` List of strings with the MIME types of all the variants that should be served for webp. ### Returns - `type VariantEditResponse struct{…}` - `ID VariantEditResponseID` The identifier of the caching setting. - `const VariantEditResponseIDVariants VariantEditResponseID = "variants"` - `Editable bool` Whether the setting is editable. - `Value VariantEditResponseValue` Value of the zone setting. - `AVIF []string` List of strings with the MIME types of all the variants that should be served for avif. - `BMP []string` List of strings with the MIME types of all the variants that should be served for bmp. - `GIF []string` List of strings with the MIME types of all the variants that should be served for gif. - `JP2 []string` List of strings with the MIME types of all the variants that should be served for jp2. - `JPEG []string` List of strings with the MIME types of all the variants that should be served for jpeg. - `JPG []string` List of strings with the MIME types of all the variants that should be served for jpg. - `JPG2 []string` List of strings with the MIME types of all the variants that should be served for jpg2. - `PNG []string` List of strings with the MIME types of all the variants that should be served for png. - `TIF []string` List of strings with the MIME types of all the variants that should be served for tif. - `TIFF []string` List of strings with the MIME types of all the variants that should be served for tiff. - `WebP []string` List of strings with the MIME types of all the variants that should be served for webp. - `ModifiedOn Time` Last time this setting was modified. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/cache" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.Cache.Variants.Edit(context.TODO(), cache.VariantEditParams{ ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), Value: cloudflare.F(cache.VariantEditParamsValue{ }), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", response.ID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "id": "variants", "editable": true, "value": { "avif": [ "image/webp", "image/jpeg" ], "bmp": [ "image/webp", "image/jpeg" ], "gif": [ "image/webp", "image/jpeg" ], "jp2": [ "image/webp", "image/avif" ], "jpeg": [ "image/webp", "image/avif" ], "jpg": [ "image/webp", "image/avif" ], "jpg2": [ "image/webp", "image/avif" ], "png": [ "image/webp", "image/avif" ], "tif": [ "image/webp", "image/avif" ], "tiff": [ "image/webp", "image/avif" ], "webp": [ "image/jpeg", "image/avif" ] }, "modified_on": "2014-01-01T05:20:00.12345Z" } } ``` ## Delete variants setting `client.Cache.Variants.Delete(ctx, body) (*VariantDeleteResponse, error)` **delete** `/zones/{zone_id}/cache/variants` Variant support enables caching variants of images with certain file extensions in addition to the original. This only applies when the origin server sends the 'Vary: Accept' response header. If the origin server sends 'Vary: Accept' but does not serve the variant requested, the response will not be cached. This will be indicated with BYPASS cache status in the response headers. ### Parameters - `body VariantDeleteParams` - `ZoneID param.Field[string]` Identifier. ### Returns - `type VariantDeleteResponse struct{…}` - `ID VariantDeleteResponseID` The identifier of the caching setting. - `const VariantDeleteResponseIDVariants VariantDeleteResponseID = "variants"` - `Editable bool` Whether the setting is editable. - `ModifiedOn Time` Last time this setting was modified. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/cache" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) variant, err := client.Cache.Variants.Delete(context.TODO(), cache.VariantDeleteParams{ ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", variant.ID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "id": "variants", "editable": true, "modified_on": "2014-01-01T05:20:00.12345Z" } } ``` ## Domain Types ### Cache Variant - `type CacheVariant struct{…}` Variant support enables caching variants of images with certain file extensions in addition to the original. This only applies when the origin server sends the 'Vary: Accept' response header. If the origin server sends 'Vary: Accept' but does not serve the variant requested, the response will not be cached. This will be indicated with BYPASS cache status in the response headers. - `ID CacheVariantID` ID of the zone setting. - `const CacheVariantIDVariants CacheVariantID = "variants"` - `ModifiedOn Time` Last time this setting was modified.