Change one setting with a PATCH request
Change one setting of an Azion API v4 resource with PATCH, or replace the whole resource with PUT and keep the settings you did not change.
You can change one setting of an Azion API v4 resource with a PATCH request. PATCH keeps every setting you leave out of the body. A PUT request replaces the whole resource instead. Most API v4 endpoints for a single resource take both methods.
The examples change a cache setting of an Application.
Prerequisites
- A personal token. To create one, refer to Manage personal tokens.
curl, to call the API, andjq, to edit the JSON body of aPUTrequest.- An Application with a cache setting. To create one, refer to Create a cache setting.
Find the ID of the cache setting
The path of one cache setting in the API carries two IDs: the Application’s and the cache setting’s.
To find the ID of the cache setting:
-
Store your token and the ID of the Application in shell variables. Replace the two values with your own:
Shell -
List the cache settings of the Application. The
fieldsparameter limits each result to its ID and name:ShellJSON -
Store the
idof the cache setting you want to change. Replace the value with thatid:
APPLICATION_ID and CACHE_SETTING_ID hold the two IDs of the cache setting’s path.
Change one setting with PATCH
A PATCH body carries only the settings to change. A setting inside a nested object, such as max_age inside browser_cache, changes alone too.
browser_cache.max_age sets the browser cache time only while browser_cache.behavior is override. With honor, Azion forwards to the browser the Cache-Control and Expires headers that your origin sends.
Send a PATCH request that sets the browser cache time to 600 seconds. Replace the three values with your own:
The response carries the whole cache setting. This excerpt shows browser_cache and modules.cache, the object that sets how long Azion keeps a copy of a response:
The browser cache time is 600 seconds, because browser_cache.behavior is override in this cache setting. The behavior of browser_cache and the modules.cache settings keep their values.
Replace the cache setting with PUT
A PUT body must carry every setting you want to keep, so you build it from a saved copy of the cache setting.
With override in modules.cache.behavior, modules.cache.max_age replaces the Cache-Control and Expires headers your origin sends. Otherwise, with honor, Azion uses max_age only when your origin sends neither header.
To replace the cache setting:
-
Save the current cache setting to a file. Replace the three values with your own:
ShellThe command prints nothing. The
cache-setting.jsonfile holds the cache setting insidedata. -
Change the copy and send it in a
PUTrequest. Thisjqfilter setsmodules.cache.max_ageto 3,600 seconds and passes everything else unchanged:ShellJSON
modules.cache.max_age is 3,600 seconds, and every other setting of the copy is unchanged. You do not need to remove the id and created_at fields of the copy: the PUT request accepts them.