Request filtering by not method(s) #487

Closed
opened 2025-12-29 15:25:04 +01:00 by adam · 1 comment
Owner

Originally created by @MichaelIDS on GitHub (Feb 17, 2023).

Currently, a mapping can be against a list of method types (GET, PUT, etc) in the JSON mapping definition.
Is there a way to map to all methods other than specific types?

For example, I want to have an early catch rejection response saying that the method is not supported, triggering for all methods other than "Get". At present, I'd need to create a mapping like the one below listing all of the method types to catch. Is this the best way?

{
        "Swagger Doc Title": "Bad Request",
        "Comment": "Bad Method type",
        "Priority": 1,
        "Request": {
            "Path": {
                "Matchers": [
                    {
                        "Name": "ExactMatcher",
                        "Pattern": "/timeEntry"
                    }
                ]
            },
            "Methods": [
                "post", "put", "delete", "patch", "connect", "trace", "head", "options"
            ]
        },
        "Response": {
            "StatusCode": 400,
            "Headers": {
                "Content-Type": "application/json"
            },
            "BodyAsJson": {
                "errorMessage": "Validation exception",
                "status": 400,
                "WireMock reason": "Bad Method type"
            },
            "UseTransformer": false
        }
    },
Originally created by @MichaelIDS on GitHub (Feb 17, 2023). Currently, a mapping can be against a list of method types (GET, PUT, etc) in the JSON mapping definition. Is there a way to map to all methods other than specific types? For example, I want to have an early catch rejection response saying that the method is not supported, triggering for all methods other than "Get". At present, I'd need to create a mapping like the one below listing all of the method types to catch. Is this the best way? ```json { "Swagger Doc Title": "Bad Request", "Comment": "Bad Method type", "Priority": 1, "Request": { "Path": { "Matchers": [ { "Name": "ExactMatcher", "Pattern": "/timeEntry" } ] }, "Methods": [ "post", "put", "delete", "patch", "connect", "trace", "head", "options" ] }, "Response": { "StatusCode": 400, "Headers": { "Content-Type": "application/json" }, "BodyAsJson": { "errorMessage": "Validation exception", "status": 400, "WireMock reason": "Bad Method type" }, "UseTransformer": false } }, ```
adam added the question label 2025-12-29 15:25:04 +01:00
adam closed this issue 2025-12-29 15:25:04 +01:00
Author
Owner

@StefH commented on GitHub (Feb 17, 2023):

For now, it's only possible to map the HTTP method using a positive matcher.
So your solutioni s correct.

@StefH commented on GitHub (Feb 17, 2023): For now, it's only possible to map the HTTP method using a positive matcher. So your solutioni s correct.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#487