Rather than routing a request to a service within your service mesh, you can send back a pre-defined body and HTTP status response to the client. If necessary, you can also specify headers by using the Header Modification feature in the enclosing route.

For more information, see the Gloo Mesh Enterprise API docs for route tables.

  1. Create a direct response route table, and specify the status and optional body that is returned. In the following example, the 510 status and no longer supported message are immediately returned in response to any requests to the /unsupported-app path.

      kubectl apply --context $REMOTE_CONTEXT1 -n global -f- <<EOF
    apiVersion: networking.gloo.solo.io/v2
    kind: RouteTable
    metadata:
      name: direct-response
      namespace: global
    spec:
      # Applies to any services within the mesh
      hosts:
        - '*'
      http:
        - name: unsupported-app-route
          # Prefix matching
          matchers:
          - uri:
              prefix: /unsupported-app
          # Immediately returns this 510 response
          directResponse:
            body: '{"message": "no longer supported"}'
            status: 510
    EOF
      
  2. Verify that you receive the expected direct response by sending a request from one service to another on the correct path in your service mesh. For example, log in to an app in your mesh and send a request to http://myapp:9080/unsupported-app. Or, you can create a temporary curl pod within your mesh.

    1. Create the curl pod.
        kubectl run -it -n bookinfo --context $REMOTE_CONTEXT1 curl \
        --image=curlimages/curl:7.73.0 --rm  -- sh
        
    2. Send a request to an app in your mesh on the /unsupported-app path.
        curl http://myapp:9080/unsupported-app -v
        
    3. Exit the temporary pod. The pod deletes itself.
        exit