Direct Response Action
Gloo Gateway allows you to specify a direct response instead of routing to a destination.
Setup
This guide assumes that you have deployed Gloo to the gloo-system
namespace and that the glooctl
command line utility
is installed on your machine. glooctl
provides several convenient functions to view, manipulate, and debug Gloo resources;
in particular, it is worth mentioning the following command, which we will use each time we need to retrieve the URL of
the Gloo Gateway that is running inside your cluster:
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:
- 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