Direct Response Action
Gloo allows you to specify a direct response instead of routing to a destination.
This guide assumes that you have installed Gloo into the
gloo-system namespace and that
glooctl is installed on your
machine. For convenience, let’s also store the URL of the Gloo Gateway in a variable 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:
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