Direct Response Action

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

Setup

This guide assumes you’ve installed Gloo into the gloo-system namespace, and glooctl is installed to your machine. Let’s also make sure $GATEWAY_URL is set in your terminal:

export GATEWAY_URL=$(glooctl proxy url)

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:
      - matcher:
          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" $GATEWAY_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