the original request
When you want to execute the request from the client process and send the response back to the server
Optional
options: FetchOptionsWhen you want to simulate a network error
When you want to fallback to the next route handler
Fetch the request using the fetch API on the client and return the response
Options for the fetch operation.
when a response cannot be resolved after FetchOptions.maxRetries
When you want to modify the real API response at runtime before sending it back to the server
client.route("**/api", (route) => {
const response = await route.fetch();
// Read the response body as JSON
const data = await response.json();
// Update the title
data.title = "Modified Title";
// Modify the response body with the modified data
const modifiedResponse = await route.modifyResponse(response, { body: JSON.stringify(data) });
// Send the modified response back to the server
return route.fulfill({ response: modifiedResponse });
})
When fulfilling a route
Options for the fulfillment.
Utility method to help with modifying responses, intended to be used in conjunction with Route.fetch for modifying responses before sending them back to the server
The response to modify.
Options for the modification.
When you want the server to process the request as is over the network, i.e. ignore the request and do not mock/modify it in any way
Route passed as an argument to the handler callback on Client.route