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
Set up HTTP method matching
-
Create an HTTPRoute resource for the
match.exampledomain 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: agentgateway-proxy namespace: agentgateway-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.exampledomain. Verify that you get back a 200 HTTP response code.curl -vi http://$INGRESS_GW_ADDRESS:80/get -H "host: match.example"curl -vi localhost:8080/get -H "host: match.example"Example output:
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 < content-length: 322 content-length: 322 < { "args": {}, "headers": { "Accept": [ "*/*" ], "Host": [ "match.example" ], "Traceparent": [ "00-30f560cded924883c1eebfecfd8a8367-3eedcde5b0a6924f-01" ], "User-Agent": [ "curl/8.7.1" ] }, "origin": "10.xxx.x.xx:55304", "url": "http://match.example/get" } -
Send another request to the httpbin app on the
match.exampledomain. This time, you use thePOSTmethod. Verify that your request is not forwarded to the httpbin app and that you get back a 404 HTTP response code.curl -vi -X POST http://$INGRESS_GW_ADDRESS:80/post -H "host: match.example"curl -vi -X POST localhost:8080/post -H "host: match.example"Example output:
< HTTP/1.1 404 Not Found HTTP/1.1 404 Not Found < content-length: 9 content-length: 9 < content-type: text/plain; charset=utf-8 content-type: text/plain; charset=utf-8
Cleanup
You can remove the resources that you created in this guide.kubectl delete httproute httpbin-match -n httpbin