Direct Response Action

Gloo Gateway allows you to specify a direct response instead of routing to a destination.

Setup

Before you begin, this guide assumes that you have the following setup.

  1. [Install Gloo Gateway]({{< versioned_link_path fromRoot="/installation/gateway/kubernetes" >}}) in the gloo-system namespace.
  2. Enable [discovery mode for Gloo Gateway]({{< versioned_link_path fromRoot="/installation/advanced_configuration/fds_mode/" >}}). If not, make sure that you created any Upstream resources with the appropriate functions.
  3. Install the glooctl command line tool.
  4. Identify the URL of the gateway proxy that you want to use for this guide, such as with the glooctl proxy command. Note that if you are testing in a local cluster such as Kind, you must use the custom localhost port that you configured instead of glooctl proxy, such as http://localhost:31500.

Creating a direct response virtual service

Let’s create a virtual service with a direct response action instead of a route action, returning a 200 “Hello, World!” response:


apiVersion: gateway.solo.io/v1
kind: VirtualService
metadata:
  name: test-direct-response
  namespace: gloo-system
spec:
  virtualHost:
    domains:
      - 'foo'
    routes:
      - matchers:
         - prefix: /
        directResponseAction:
          status: 200
          body: "Hello, world!"

Now if we curl the route, we should get the 200 response and see the message:

curl -H "Host: foo" $(glooctl proxy url)

This will return the following message:

Hello, world!

Summary

A virtual service route can be configured with a direct response instead of a routing action.

Let’s clean up the virtual service we created:


kubectl delete vs -n gloo-system test-direct-response

glooctl delete vs test-direct-response