Skip to content

Method Matcher

The Method matcher allows a rule to match requests based on the HTTP method. It is the primary way to differentiate between read operations (GET), write operations (POST, PUT, PATCH), and deletion operations (DELETE) without inspecting the request body or URL.

The Method matcher only determines whether a rule should run. Once a request matches, the rule’s configured handlers execute.

To learn how rules work, see Hostgrid Rules.


The Method matcher evaluates the HTTP method of the incoming request.

For the request:

POST https://example.com/api/users HTTP/1.1

The components are:

ComponentValue
MethodPOST
Hostexample.com
Path/api/users
Headers(varies)

Only the method is evaluated by this matcher.

The path, headers, and query parameters are matched using their own matcher types.

The Method matcher recognizes standard HTTP methods:

MethodTypical use
GETRetrieve a resource
POSTCreate a resource or submit data
PUTReplace a resource entirely
PATCHPartially update a resource
DELETERemove a resource

The Method matcher supports the following comparison operators.

OperatorDescriptionExample
is equal toMatches an exact HTTP method.POST matches only POST requests.
is not equal toMatches every method except the specified one.POST matches GET, PUT, PATCH and DELETE

Unlike the Path matcher, the Method matcher does not support prefix, suffix, or substring operators. HTTP methods are discrete values, so exact comparison is sufficient.


To match only POST requests, such as form submissions or API creates:

Operator: is equal to
Value: POST

Method Matcher – is equal to

API representation:

{
"type": "method",
"params": { "operator": "is", "value": "POST" }
}

To match any request except DELETE:

Operator: is not equal to
Value: DELETE

Method Matcher – is not equal to

API representation:

{
"type": "method",
"params": { "operator": "is_not", "value": "DELETE" }
}

Combining the Method matcher with other matchers

Section titled “Combining the Method matcher with other matchers”

A rule can contain multiple matchers. When multiple matchers are configured, all of them must match before the rule executes.

This makes the Method matcher most useful when combined with other matchers to target specific operations on specific resources.

Matcher combinationWhat it matches
Method POST + Path /api/usersOnly POST requests to /api/users
Method DELETE + Header X-Admin: trueOnly DELETE requests that include an admin header
Method GET + Query draft=trueOnly GET requests with draft=true in the query string

Similarly, you can combine the Method matcher with:


The Method matcher is most effective when paired with a handler that takes a different action depending on the type of request.

Use caseMethod matcherHandler
Block destructive operations on a public APIis equal to DELETEStatic Response returning a 403 or 405 error. See Static Response Handler.
Add authentication headers to write requestsis not equal to GETRequest Headers to inject an auth token for non-read operations. See Request Headers Handler.
Redirect POST form submissions to a new endpointis equal to POSTRedirect to the updated form processing URL. See Redirect Handler.
Enforce read-only mode during maintenanceis not equal to GETStatic Response returning a “read-only mode” message for any non-GET request. See Static Response Handler.
Log or flag all write operations via headersis equal to POSTRequest Headers to add a debugging header before forwarding to the upstream. See Request Headers Handler.

  • Use the Method matcher to separate read traffic from write traffic when they need different handling.
  • Pair the Method matcher with the Path matcher to target specific API endpoints rather than applying method-based rules broadly.
  • Remember that browsers typically use GET for page navigation and POST for form submissions. API clients may use PUT, PATCH, and DELETE as well.

If a rule with a Method matcher is not matching as expected:

  • Check method casing. HTTP methods are case-sensitive in the matcher. post does not match POST.
  • Verify the actual method. Use browser developer tools (Network tab) or server logs to confirm the method being sent. Some frameworks or proxies may convert methods (e.g., POST with _method=PUT in the body).
  • Review operator selection. is not equal to POST matches every non-POST request, not just GET requests.
  • Check matcher combinations. If the rule has multiple matchers, confirm that every matcher evaluates to true. A Path matcher that does not match will prevent the rule from running even if the Method matcher does.
  • Consider rule order. Hostgrid executes all matching rules in order. If an earlier rule contains a Redirect or Static Response handler, later rules will not execute for that request.

For more information about rule evaluation, see Hostgrid Rules.