HTTP method
Specify an HTTP method, such as POST, GET, PUT, PATCH, or DELETE, to match requests against.
For more information, see the Kubernetes Gateway API documentation.
Before you begin
Follow the Get started guide to install Gloo Gateway, set up a gateway resource, and deploy the httpbin sample app.
Get the external address of the gateway and save it in an environment variable.
Set up HTTP method matching
Create an HTTPRoute resource for the
match.example
domain that serves incoming GET requests for the httpbin app.kubectl apply -f- <<EOF apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin-match namespace: httpbin spec: parentRefs: - name: http namespace: gloo-system hostnames: - match.example rules: - matches: - method: "GET" backendRefs: - name: httpbin port: 8000 EOF
Send a GET request to the httpbin app on the
match.example
domain. Verify that you get back a 200 HTTP response code.Example output:
* Mark bundle as not supporting multiuse < HTTP/1.1 200 OK HTTP/1.1 200 OK < access-control-allow-credentials: true access-control-allow-credentials: true < access-control-allow-origin: * access-control-allow-origin: * < content-type: application/json; encoding=utf-8 content-type: application/json; encoding=utf-8 < date: Sat, 04 Nov 2023 03:34:12 GMT date: Sat, 04 Nov 2023 03:34:12 GMT < content-length: 422 content-length: 422 < x-envoy-upstream-service-time: 1 x-envoy-upstream-service-time: 1 < server: envoy server: envoy < { "args": {}, "headers": { "Accept": [ "*/*" ], "Host": [ "match.example:8080" ], "User-Agent": [ "curl/7.77.0" ], "X-Envoy-Expected-Rq-Timeout-Ms": [ "15000" ], "X-Forwarded-Proto": [ "http" ], "X-Request-Id": [ "6823bc28-ba8e-47df-a3a0-1aa21628db0e" ] }, "origin": "10.116.3.7:47022", "url": "http://match.example:8080/get" }
Send another request to the httpbin app on the
match.example
domain. This time, you use thePOST
method. Verify that your request is not forwarded to the httpbin app and that you get back a 404 HTTP response code.Example output:
* Mark bundle as not supporting multiuse < HTTP/1.1 404 Not Found HTTP/1.1 404 Not Found < date: Tue, 23 Apr 2024 18:47:53 GMT date: Tue, 23 Apr 2024 18:47:53 GMT < server: envoy server: envoy < content-length: 0 content-length: 0 ...
Cleanup
You can optionally delete the HTTP route that you created as part of this guide.
kubectl delete httproute httpbin-match -n httpbin