synthetic statement replaces the content of the cache object's response body with the specified string, when processing an error state.
Typically, synthetic responses are used to create customised error messages or responses to API calls, but can be used to serve full pages of content, and are often employed for site-wide metadata such as
STRING, if the
content argument to the
synthetic statement contains any null bytes (
0x00), the first instance of a null byte will terminate the string.
synthetic is therefore not a good choice for generating non-textual content, and you may prefer to use
synthetic is used in the following code examples. Examples apply VCL to real-world use cases and can be deployed as they are, or adapted for your own service. See the full list of code examples for more inspiration.
Click RUN on a sample below to provision a Fastly service, execute the code on Fastly, and see how the function behaves.
Convert timestamps to relative times like '2 hours ago'
Serve robots.txt from the edge
Include full text of robots.txt in VCL and serve as a synthetic response to avoid robots.txt requests hitting your origin.
Client public IP API at the edge
Quickly fetch the user's public IP from an API endpoint on your own domain, with no origin.