LOG IN SIGN UP
Documentation

Responses tutorial

Fastly allows you to create custom HTTP responses that are served directly from the cache without storing the page on a server. Responses are commonly used to serve small static assets that seldom change and maintenance pages that are served when origins are unavailable. This tutorial shows you how to create your own responses.

Overview

A response has three basic attributes:

By setting these three attributes and adding a condition to the response, you can very quickly get one up and running on your service. Let's get started!

Creating a response

  1. Log in to the Fastly application and click the configure tab (wrench icon).

    the Configure tab

  2. From the Service menu, select the appropriate service and then click the blue Configure button. The main controls for your selected service appear.

  3. Click Content from the section list on the left.

    the Content tab

  4. In the Responses area at the bottom of the page, click the New button. The New Response window appears.

    the text editor area of the New Response window

  5. Fill out the New Response fields as follows:

    • In the Name field, type a human-readable name for the response (e.g., "My First Response")
    • From the Status menu, select the appropriate status (e.g., 200 OK).
    • In the MIME Type field, type the content type of the response (e.g., text/html).
    • In the main text field, type the response you want to appear when the conditions are met.
  6. Click the Create button to create your custom response.

Your new response appears in the list of responses.

Adding conditions

  1. Click on the gear menu, and then select Request Conditions.

    the Request Conditions selection on the New Response editing menu

  2. If you have not yet added any conditions to your service, the New Condition window will appear automatically. If the new form does not appear, click New.

    the Apply If field  associated with a new response

  3. Fill out the New Condition fields as follows:

    • In the Name field, type a human-readable name for the condition so that it can be easily identified in the future.
    • In the Apply If... field, type the condition under which the new response occurs. The condition should take the following format: req.url ~ “^/construction/“ equals the request condition you're creating the response for. The Conditions subcategory has more detailed information on conditions.
    • In the Priority field, type a priority if needed. Condition priorities are only needed in "interesting" cases, and can usually be left at the default "10" for all response conditions.
  4. Click the Create button. The condition will be created and applied to the custom response object.

  5. Deploy the service.

Fastly will now serve your custom response page when the condition is met.