Response Orchestration, also known as Dynamic Content Assembly, is the ability to create on-the-fly response data and content.
You can use Response Orchestration to dynamically create tailored, personalized data or web content for a specific set of users or devices. You can also source data and content from multiple server-side APIs or content origins. Response Orchestration supports conditions when combining multiple data sets or HTML fragments.
Edgeworkers provides two mechanisms for returning response objects to the client from the edge:
responseProvider event handler to generate and manipulate response bodies within an EdgeWorkers function. When building your Edge solutions, you can fetch resources from other external origins and add them directly or indirectly into the main response body. With
responseProvider you can make Edge decisions, build content, and optionally cache response output.
The diagram below illustrates how the
responseProvider function generates a response, acting as a surrogate origin.
responseProvider event fails, for example as a result of an error, the request is forwarded to the origin.
respondWith method is available from
respondWith event is typically used to prevent a request from going to origin, and to return a response, such as a redirect, from the edge.
To help you learn more about how to use the
responseProvider event handler, we've added code samples to the Edgeworkers GitHub Repository.
Response Orchestration example
In this Response manipulation example we use an EdgeWorkers function to modify an HTML response stream by adding content to the response. The script adds the content to the page just before the closing head tag.
You can modify this example to support the addition of various types of scripts to other sections of the HTML. You can also use HTTP sub-request functionality to dynamically add content to the page.
API Orchestration example
This API Orchestration example demonstrates how to use an EdgeWorkers function to merge multiple internal APIs into a single API response that is delivered to the user.
HTTP sub-requests made from EdgeWorkers functions provide numerous possibilities to generate API responses.
Updated 7 months ago