#### Basic Expectation

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "method": "GET",
    "path": "/view/cart",
    "queryStringParameters": {
      "cartId": [
        "055CA455-1DF7-45BB-8535-4F83E7266092"
      ]
    },
    "cookies": {
      "session": "4930456C-C718-476F-971F-CB8E047AB349"
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Add Array Of Expectations

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '[
  {
    "httpRequest": {
      "path": "/somePathOne"
    },
    "httpResponse": {
      "statusCode": 200,
      "body": {
        "value": "one"
      }
    }
  },
  {
    "httpRequest": {
      "path": "/somePathTwo"
    },
    "httpResponse": {
      "statusCode": 200,
      "body": {
        "value": "one"
      }
    }
  },
  {
    "httpRequest": {
      "path": "/somePathThree"
    },
    "httpResponse": {
      "statusCode": 200,
      "body": {
        "value": "one"
      }
    }
  }
]
```

#### Class Callback

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some.*"
  },
  "httpClassCallback": {
    "callbackClass": "org.mockserver.examples.mockserver.CallbackActionExamples$TestExpectationCallback"
  }
}'
```

#### Verify Requests Exact

```bash
curl -X PUT 'localhost:1080/mockserver/verify' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "times": {
    "atLeast": 2,
    "atMost": 2
  }
}'
```

#### Verify Requests Receive At Least Twice

```bash
curl -X PUT 'localhost:1080/mockserver/verify' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "times": {
    "atLeast": 2
  }
}'
```

#### Verify Requests Receive At Most Twice

```bash
curl -X PUT 'localhost:1080/mockserver/verify' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "times": {
    "atMost": 2
  }
}'
```

#### Verify Requests Receive Exactly Twice

```bash
curl -X PUT 'localhost:1080/mockserver/verify' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "times": {
    "atLeast": 2,
    "atMost": 2
  }
}'
```

#### Verify Requests Receive At Least Twice By OpenAPI

```bash
curl -X PUT 'localhost:1080/mockserver/verify' \
-d '{
  "httpRequest": {
    "specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"
  },
  "times": {
    "atLeast": 2,
    "atMost": 2
  }
}'
```

#### Verify Requests Receive At Least Twice By OpenAPI With Operation

```bash
curl -X PUT 'localhost:1080/mockserver/verify' \
-d '{
  "httpRequest": {
    "specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json",
    "operationId": "showPetById"
  },
  "times": {
    "atLeast": 2,
    "atMost": 2
  }
}'
```

#### Verify Request Sequence

```bash
curl -X PUT 'localhost:1080/mockserver/verifySequence' \
-d '[
  {
    "path": "/some/path/one"
  },
  {
    "path": "/some/path/two"
  },
  {
    "path": "/some/path/three"
  }
]
```

#### Verify Request Sequence Using Open API

```bash
curl -X PUT 'localhost:1080/mockserver/verifySequence' \
-d '[
  {
    "path": "/status"
  },
  {
    "specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
    "operationId": "listPets"
  },
  {
    "specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json",
    "operationId": "showPetById"
  }
]
```
#### Verify Request Sequence Using Open API

```bash
curl -X PUT 'localhost:1080/mockserver/verifySequence' \
-d '[
  {
    "id": "31e4ca35-66c6-4645-afeb-6e66c4ca0559"
  },
  {
    "id": "66c6ca35-ca35-66f5-8feb-5e6ac7ca0559"
  },
  {
    "id": "ca3531e4-23c8-ff45-88f5-4ca0c7ca0559"
  }
]
```

#### Retrieve Recorded Requests Filtered By Request Matcher

```bash
curl -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUESTS&format=JSON"
-d '{
    "path": "/some/path",
    "method": "POST"
}'
```

#### Retrieve Recorded Log Messages Filtered By Request Matcher

```bash
curl -X PUT "http://localhost:1080/mockserver/retrieve?type=LOGS" \
-d '{
    "path": "/some/path",
    "method": "POST"
}'
```

#### Clear With Request Properties Matcher


```bash
curl -X PUT "http://localhost:1080/mockserver/clear" -d '{
    "path": "/some/path"
}'
```

#### Clear With Open API Request Matcher

```bash
curl -X PUT "http://localhost:1080/mockserver/clear" -d '{
    "specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json",
    "operationId": "showPetById"
}'
```

#### Clear With Expectation Id

```bash
curl -X PUT "http://localhost:1080/mockserver/clear" -d '{
    "id": "31e4ca35-66c6-4645-afeb-6e66c4ca0559"
}'
```

#### Clear Requests And Logs With Request Properties Matcher

```bash
curl -X PUT "http://localhost:1080/mockserver/clear?type=log" -d '{
    "path": "/some/path"
}'
```

#### Clear Requests And Logs With Open API Request Properties Matcher

```bash
curl -X PUT "http://localhost:1080/mockserver/clear?type=log" -d '{
    "specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json",
    "operationId": "showPetById"
}'
```

#### Reset

```bash
curl -X PUT "http://localhost:1080/mockserver/reset
```

#### Random Bytes Error

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpError": {
    "dropConnection": true,
    "responseBytes": "eQqmdjEEoaXnCvcK6lOAIZeU+Pn+womxmg=="
  }
}'
```

#### Drop Connection Error

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpError": {
    "dropConnection": true
  }
}'
```

#### Forward Request In HTTP

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpForward": {
    "host": "mock-server.com",
    "port": 80,
    "scheme": "HTTP"
  }
}'
```

#### Forward Request In HTTPS

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpForward": {
    "host": "mock-server.com",
    "port": 443,
    "scheme": "HTTPS"
  }
}'
```

#### Forward Overridden Request

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpOverrideForwardedRequest": {
    "httpRequest": {
      "path": "/some/other/path",
      "headers": {
        "Host": [
          "target.host.com"
        ]
      }
    }
  }
}'
```

#### Forward Overridden Request And Response

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpOverrideForwardedRequest": {
    "httpRequest": {
      "path": "/some/other/path",
      "headers": {
        "Host": [
          "target.host.com"
        ]
      }
    },
    "httpResponse": {
      "body": "some_overridden_body"
    }
  }
}'
```

#### Forward Overridden And Modified Request

```bash
curl -X PUT "http://localhost:1080/mockserver/expectation" -d '{
    "httpRequest": {
        "path": "/some/path"
    },
    "httpOverrideForwardedRequest": {
        "requestOverride": {
            "headers": {
                "Host": [
                    "target.host.com"
                ]
            }, 
            "body": "some_overridden_body"
        }, 
        "requestModifier": {
            "cookies": {
                "add": {
                    "cookieToAddOne": "addedValue", 
                    "cookieToAddTwo": "addedValue"
                }, 
                "remove": [
                    "overrideCookieToRemove", 
                    "requestCookieToRemove"
                ], 
                "replace": {
                    "overrideCookieToReplace": "replacedValue", 
                    "requestCookieToReplace": "replacedValue", 
                    "extraCookieToReplace": "shouldBeIgnore"
                }
            }, 
            "headers": {
                "add": {
                    "headerToAddTwo": [
                        "addedValue"
                    ], 
                    "headerToAddOne": [
                        "addedValue"
                    ]
                }, 
                "remove": [
                    "overrideHeaderToRemove", 
                    "requestHeaderToRemove"
                ], 
                "replace": {
                    "requestHeaderToReplace": [
                        "replacedValue"
                    ], 
                    "overrideHeaderToReplace": [
                        "replacedValue"
                    ], 
                    "extraHeaderToReplace": [
                        "shouldBeIgnore"
                    ]
                }
            }, 
            "path": {
                "regex": "^/(.+)/(.+)$", 
                "substitution": "/prefix/$1/infix/$2/postfix"
            }, 
            "queryStringParameters": {
                "add": {
                    "parameterToAddTwo": [
                        "addedValue"
                    ], 
                    "parameterToAddOne": [
                        "addedValue"
                    ]
                }, 
                "remove": [
                    "overrideParameterToRemove", 
                    "requestParameterToRemove"
                ], 
                "replace": {
                    "requestParameterToReplace": [
                        "replacedValue"
                    ], 
                    "overrideParameterToReplace": [
                        "replacedValue"
                    ], 
                    "extraParameterToReplace": [
                        "shouldBeIgnore"
                    ]
                }
            }
        }
    }
}'
```

#### Forward Overridden And Modified Request And Response

```bash
curl -X PUT "http://localhost:1080/mockserver/expectation" -d '{
    "httpRequest": {
        "path": "/some/path"
    },
    "httpOverrideForwardedRequest": {
        "requestOverride": {
            "headers": {
                "Host": [
                    "target.host.com"
                ]
            }, 
            "body": "some_overridden_body"
        }, 
        "requestModifier": {
            "cookies": {
                "add": {
                    "cookieToAddOne": "addedValue", 
                    "cookieToAddTwo": "addedValue"
                }, 
                "remove": [
                    "overrideCookieToRemove", 
                    "requestCookieToRemove"
                ], 
                "replace": {
                    "overrideCookieToReplace": "replacedValue", 
                    "requestCookieToReplace": "replacedValue", 
                    "extraCookieToReplace": "shouldBeIgnore"
                }
            }, 
            "headers": {
                "add": {
                    "headerToAddTwo": [
                        "addedValue"
                    ], 
                    "headerToAddOne": [
                        "addedValue"
                    ]
                }, 
                "remove": [
                    "overrideHeaderToRemove", 
                    "requestHeaderToRemove"
                ], 
                "replace": {
                    "requestHeaderToReplace": [
                        "replacedValue"
                    ], 
                    "overrideHeaderToReplace": [
                        "replacedValue"
                    ], 
                    "extraHeaderToReplace": [
                        "shouldBeIgnore"
                    ]
                }
            }, 
            "path": {
                "regex": "^/(.+)/(.+)$", 
                "substitution": "/prefix/$1/infix/$2/postfix"
            }, 
            "queryStringParameters": {
                "add": {
                    "parameterToAddTwo": [
                        "addedValue"
                    ], 
                    "parameterToAddOne": [
                        "addedValue"
                    ]
                }, 
                "remove": [
                    "overrideParameterToRemove", 
                    "requestParameterToRemove"
                ], 
                "replace": {
                    "requestParameterToReplace": [
                        "replacedValue"
                    ], 
                    "overrideParameterToReplace": [
                        "replacedValue"
                    ], 
                    "extraParameterToReplace": [
                        "shouldBeIgnore"
                    ]
                }
            }
        }, 
        "responseOverride": {
            "body": "some_overridden_body"
        },
        "responseModifier": {
            "cookies": {
                "add": {
                    "cookieToAddOne": "addedValue", 
                    "cookieToAddTwo": "addedValue"
                }, 
                "remove": [
                    "overrideCookieToRemove", 
                    "requestCookieToRemove"
                ], 
                "replace": {
                    "overrideCookieToReplace": "replacedValue", 
                    "requestCookieToReplace": "replacedValue", 
                    "extraCookieToReplace": "shouldBeIgnore"
                }
            }, 
            "headers": {
                "add": {
                    "headerToAddTwo": [
                        "addedValue"
                    ], 
                    "headerToAddOne": [
                        "addedValue"
                    ]
                }, 
                "remove": [
                    "overrideHeaderToRemove", 
                    "requestHeaderToRemove"
                ], 
                "replace": {
                    "requestHeaderToReplace": [
                        "replacedValue"
                    ], 
                    "overrideHeaderToReplace": [
                        "replacedValue"
                    ], 
                    "extraHeaderToReplace": [
                        "shouldBeIgnore"
                    ]
                }
            }
        }
    }
}'
```

#### Forward Overridden Request And Change Host And Port

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpOverrideForwardedRequest": {
    "httpRequest": {
      "path": "/some/other/path",
      "headers": {
        "Host": [
          "any.host.com"
        ]
      },
      "socketAddress": {
        "host": "target.host.com",
        "port": 1234,
        "scheme": "HTTPS"
      }
    }
  }
}'
```

#### Forward Overridden Request With Delay

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpOverrideForwardedRequest": {
    "httpRequest": {
      "path": "/some/other/path",
      "headers": {
        "Host": [
          "target.host.com"
        ]
      }
    },
    "delay": {
      "timeUnit": "SECONDS",
      "value": 20
    }
  }
}'
```

#### Forward Using Javascript Template

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpForwardTemplate": {
    "template": "return {'path' : \"/somePath\", 'queryStringParameters' : {'userId' : request.queryStringParameters && request.queryStringParameters['userId']},'headers' : {'Host' : [ \"localhost:1081\" ]}, 'body': {'name': 'value'}};",
    "templateType": "JAVASCRIPT"
  }
}'
```

#### Forward Using Javascript Template With Delay

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpForwardTemplate": {
    "template": "return {'path' : \"/somePath\", 'cookies' : {'SessionId' : request.cookies && request.cookies['SessionId']}, 'headers' : {'Host' : [ \"localhost:1081\" ]},'keepAlive' : true, 'secure' : true, 'body' : \"some_body\"};",
    "templateType": "JAVASCRIPT",
    "delay": {
      "timeUnit": "SECONDS",
      "value": 20
    }
  }
}'
```

#### Forward Using Velocity Template

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpForwardTemplate": {
    "template": "{'path' : \"/somePath\", 'queryStringParameters' : { 'userId' : [ \"$!request.queryStringParameters['userId'][0]\" ]},'cookies' : {'SessionId' : \"$!request.cookies['SessionId']\"},'headers' : {'Host' : [ \"localhost:1081\" ]}, 'body': \"{'name': 'value'}\"}",
    "templateType": "VELOCITY"
  }
}'
```

#### Open API Expectations Loaded By HTTP URL

NOT JSON

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"
}'
```

#### Open API Expectations Operation

NOT JSON

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json",
    "operationId": "showPetById"
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Open API Expectations Loaded By Classpath Location

NOT JSON

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json"
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Request Matcher By Open API Loaded By HTTP URL

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json"
}'
```

#### Request Matcher By Open API Operation

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json",
    "operationId": "showPetById"
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Request Matcher By Open API Loaded By Classpath Location

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "specUrlOrPayload": "org/mockserver/openapi/openapi_petstore_example.json"
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Update Expectation By Id

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "id": "630a6e5b-9d61-4668-a18f-a0d3df558583",
  "priority": 0,
  "httpRequest": {
    "specUrlOrPayload": "https://raw.githubusercontent.com/mock-server/mockserver-monorepo/master/mockserver/mockserver-integration-testing/src/main/resources/org/mockserver/openapi/openapi_petstore_example.json",
    "operationId": "showPetById"
  },
  "httpResponse": {
    "statusCode": 200,
    "body": "some_response_body"
  },
  "times": {
    "unlimited": true
  },
  "timeToLive": {
    "unlimited": true
  }
}'
```

#### Match Request By Path

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Path Exactly Twice

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpResponse": {
    "body": "some_response_body"
  },
  "times": {
    "remainingTimes": 2,
    "unlimited": false
  },
  "timeToLive": {
    "unlimited": true
  }
}'
```

#### Match Request By Path Exactly Once In The Next 60 Seconds

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpResponse": {
    "body": "some_response_body"
  },
  "times": {
    "remainingTimes": 1,
    "unlimited": false
  },
  "timeToLive": {
    "timeUnit": "SECONDS",
    "timeToLive": 60,
    "unlimited": false
  }
}'
```

#### Match Request By Regex Path

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some.*"
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Not Matching Path

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "!/some.*"
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Method Regex

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "method": "P.*{2,3}"
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Not Matching Method

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "method": "!GET"
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Path And Path Parameters And Query Parameters Name

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path/{cartId}",
    "pathParameters": {
      "cartId": [
        "055CA455-1DF7-45BB-8535-4F83E7266092"
      ]
    },
    "queryStringParameters": {
      "type": [
        "[A-Z0-9\\-]+"
      ]
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Path Parameter Regex Value

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path/{cartId}",
    "pathParameters": {
      "cartId": [
        "[A-Z0-9\\-]+"
      ]
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Path Parameter Json Schema Value

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path/{cartId}/{maxItemCount}",
    "pathParameters": {
      "cartId": [
        {
          "schema": {
            "type": "string",
            "pattern": "^[A-Z0-9-]+$"
          }
        }
      ],
      "maxItemCount": [
        {
          "schema": {
            "type": "integer"
          }
        }
      ]
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Query Parameter Regex Name

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path",
    "queryStringParameters": {
      "[A-z]{0,10}": [
        "055CA455-1DF7-45BB-8535-4F83E7266092"
      ]
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Query Parameter Regex Value

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path",
    "queryStringParameters": {
      "cartId": [
        "[A-Z0-9\\-]+"
      ]
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Optional Query Parameter Regex Value

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path",
    "queryStringParameters": {
      "?cartId": [
        "[A-Z0-9\\-]+"
      ],
      "?maxItemCount": [
        {
          "schema": {
            "type": "integer"
          }
        }
      ],
      "?userId": [
        {
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Query Parameter Json Schema Value

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path",
    "queryStringParameters": {
      "cartId": [
        {
          "schema": {
            "type": "string",
            "pattern": "^[A-Z0-9-]+$"
          }
        }
      ],
      "maxItemCount": [
        {
          "schema": {
            "type": "integer"
          }
        }
      ]
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Query Parameter Sub Set

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path",
    "queryStringParameters": {
      "multiValuedParameter": [
        {
          "schema": {
            "type": "string",
            "pattern": "^[A-Z0-9-]+$"
          }
        }
      ],
      "maxItemCount": [
        {
          "schema": {
            "type": "integer"
          }
        }
      ]
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Query Parameter Key Matching

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path",
    "queryStringParameters": {
      "keyMatchStyle": "MATCHING_KEY",
      "multiValuedParameter": [
        {
          "schema": {
            "type": "string",
            "pattern": "^[A-Z0-9-]+$"
          }
        }
      ],
      "maxItemCount": [
        {
          "schema": {
            "type": "integer"
          }
        }
      ]
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Headers

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "method": "GET",
    "path": "/some/path",
    "headers": {
      "Accept": [
        "application/json"
      ],
      "Accept-Encoding": [
        "gzip, deflate, br"
      ]
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Header Name Regex

Matches requests that have any header starting with the name Accept

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path",
    "headers": {
      "Accept.*": []
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Header Regex Name And Value

Matches requests that have a header with a name starting with Accept and a value containing gzip

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path",
    "headers": {
      "Accept.*": [
        ".*gzip.*"
      ]
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Header Json Schema Value

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path",
    "headers": {
      "Accept.*": [
        {
          "schema": {
            "type": "string",
            "pattern": "^.*gzip.*$"
          }
        }
      ]
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Either Or Optional Header

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path",
    "headers": {
      "headerOne|headerTwo": [
        ".*"
      ],
      "?headerOne": [
        "headerOneValue"
      ],
      "?headerTwo": [
        "headerTwoValue"
      ]
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Either Or Optional Header

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "id": "2c4f2747-bf8f-42dc-8c82-99f497884cfa",
  "priority": 0,
  "httpRequest": {
    "path": "/some/path",
    "headers": {
      "headerOne|headerTwo": [
        ".*"
      ],
      "?headerOne": [
        "headerOneValue"
      ],
      "?headerTwo": [
        "headerTwoValue"
      ]
    }
  },
  "times": {
    "unlimited": true
  },
  "timeToLive": {
    "unlimited": true
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Header Key Matching

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path",
    "headers": {
      "keyMatchStyle": "MATCHING_KEY",
      "multiValuedHeader": [
        "value.*"
      ],
      "headerTwo": [
        "headerTwoValue"
      ]
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Not Matching Header Value

Matches requests that have an Accept header without the value "application/json" and that have an Accept-Encoding without the substring "gzip"

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path",
    "headers": {
      "Accept": [
        "!application/json"
      ],
      "Accept-Encoding": [
        "!.*gzip.*"
      ]
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Not Matching Headers

Matches requests that do not have either an Accept or an Accept-Encoding header

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path",
    "headers": {
      "!Accept": [
        ".*"
      ],
      "!Accept-Encoding": [
        ".*"
      ]
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Cookies And Query Parameters

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "method": "GET",
    "path": "/view/cart",
    "queryStringParameters": {
      "cartId": [
        "055CA455-1DF7-45BB-8535-4F83E7266092"
      ]
    },
    "cookies": {
      "session": "4930456C-C718-476F-971F-CB8E047AB349"
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Cookies And Query Parameter Json Schema Values

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "method": "GET",
    "path": "/view/cart",
    "queryStringParameters": {
      "cartId": [
        {
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "cookies": {
      "session": {
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      }
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Optional Cookies And Query Parameter Json Schema Values

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/view/cart",
    "queryStringParameters": {
      "cartId": [
        {
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ]
    },
    "cookies": {
      "?session": {
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      }
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Regex Body

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "body": "starts_with_.*"
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Body In UTF 16

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "body": {
      "type": "STRING",
      "string": "我说中国话",
      "contentType": "text/plain; charset=utf-16"
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Body With Form Submission

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "method": "POST",
    "headers": {
      "Content-Type": [
        "application/x-www-form-urlencoded"
      ]
    },
    "body": {
      "type": "PARAMETERS",
      "parameters": {
        "email": [
          "joe.blogs@gmail.com"
        ],
        "password": [
          "secure_Password123"
        ]
      }
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Body With XPath

Matches any request with an XML body containing an element that matches the XPath expression, for example with the following body:

```xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
    <book category="COOKING">
        <title lang="en">Everyday Italian</title>
        <author>Giada De Laurentiis</author>
        <year>2005</year>
        <price>30.00</price>
    </book>
    <book category="CHILDREN">
        <title lang="en">Harry Potter</title>
        <author>J K. Rowling</author>
        <year>2005</year>
        <price>29.99</price>
    </book>
    <book category="WEB">
        <title lang="en">Learning XML</title>
        <author>Erik T. Ray</author>
        <year>2003</year>
        <price>31.95</price>
    </book>
</bookstore>
```

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "body": {
      "type": "XPATH",
      "xpath": "/bookstore/book[price>30]/price"
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Not Matching Body With XPath

Matches any request with an XML body that does NOT contain an element that matches the XPath expression

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "body": {
      "not": true,
      "type": "XPATH",
      "xpath": "/bookstore/book[price>30]/price"
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Body With Xml

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "body": {
      "type": "XML",
      "xml": "<bookstore><book nationality=\"ITALIAN\" category=\"COOKING\"><title lang=\"en\">Everyday Italian</title><author>Giada De Laurentiis</author><year>2005</year><price>30.00</price></book></bookstore>"
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Body With Xml With Placeholders

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "body": {
      "type": "XML",
      "xml": "<bookstore><book nationality=\"ITALIAN\" category=\"COOKING\"><title lang=\"en\">Everyday Italian</title><author>${xmlunit.ignore}</author><year>${xmlunit.isNumber}</year><price>30.00</price></book></bookstore>"
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Body With Xml Schema

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "body": {
      "type": "XML_SCHEMA",
      "xmlSchema": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema xmlns:xs=\"https://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\"><!-- XML Schema Generated from XML Document on Wed Jun 28 2017 21:52:45 GMT+0100 (BST) --><!-- with XmlGrid.net Free Online Service https://xmlgrid.net --><xs:element name=\"notes\"><xs:complexType><xs:sequence><xs:element name=\"note\" maxOccurs=\"unbounded\"><xs:complexType><xs:sequence><xs:element name=\"to\" minOccurs=\"1\" maxOccurs=\"1\" type=\"xs:string\"></xs:element><xs:element name=\"from\" minOccurs=\"1\" maxOccurs=\"1\" type=\"xs:string\"></xs:element><xs:element name=\"heading\" minOccurs=\"1\" maxOccurs=\"1\" type=\"xs:string\"></xs:element><xs:element name=\"body\" minOccurs=\"1\" maxOccurs=\"1\" type=\"xs:string\"></xs:element></xs:sequence></xs:complexType></xs:element></xs:sequence></xs:complexType></xs:element>\n</xs:schema>"
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Body With Json Exactly

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "body": {
      "type": "JSON",
      "json": {
        "id": 1,
        "name": "A green door",
        "price": 12.50,
        "tags": [
          "home",
          "green"
        ]
      },
      "matchType": "STRICT"
    }
  },
  "httpResponse": {
    "statusCode": 202,
    "body": "some_response_body"
  }
}'
```

#### Match Request By Body With Json Ignoring Extra Fields

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "body": {
      "type": "JSON",
      "json": {
        "id": 1,
        "name": "A green door",
        "price": 12.50,
        "tags": [
          "home",
          "green"
        ]
      }
    }
  },
  "httpResponse": {
    "statusCode": 202,
    "body": "some_response_body"
  }
}'
```

#### Match Request By Body With Json Ignoring Extra Fields In Array Objects

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "method": "POST",
    "path": "/json",
    "body": {
      "type": "JSON",
      "json": {
        "context": [
          {
            "source": "DECISION_REQUEST"
          },
          {
            "source": "DECISION_REQUEST"
          },
          {
            "source": "DECISION_REQUEST"
          }
        ]
      },
      "matchType": "ONLY_MATCHING_FIELDS"
    }
  },
  "httpResponse": {
    "statusCode": 200,
    "body": "some response"
  },
  "times": {
    "remainingTimes": 1,
    "unlimited": true
  }
}'
```

#### Match Request By Body With Json With Placeholders

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "body": {
      "type": "JSON",
      "json": {
        "id": 1,
        "name": "A green door",
        "price": "${json-unit.ignore-element}",
        "enabled": "${json-unit.any-boolean}",
        "tags": [
          "home",
          "green"
        ]
      }
    }
  },
  "httpResponse": {
    "statusCode": 202,
    "body": "some_response_body"
  }
}'
```

#### Match Request By Body With Json Schema

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "body": {
      "type": "JSON_SCHEMA",
      "jsonSchema": {
        "$schema": "https://json-schema.org/draft-04/schema#",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "id": {
            "description": "The unique identifier for a product",
            "type": "integer"
          },
          "name": {
            "description": "Name of the product",
            "type": "string"
          },
          "price": {
            "type": "number",
            "minimum": 0,
            "exclusiveMinimum": true
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1,
            "uniqueItems": true
          }
        },
        "required": [
          "id",
          "name",
          "price"
        ]
      }
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Body With Json Path

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "body": {
      "type": "JSON_PATH",
      "jsonPath": "$.store.book[?(@.price < 10)]"
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request By Not Matching Body With Json Path

Matches any request with an JSON body that does NOT contain one or more fields that match the JsonPath expression

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "body": {
      "not": true,
      "type": "JSON_PATH",
      "jsonPath": "$.store.book[?(@.price < 10)]"
    }
  },
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request All Requests

If no request matcher is specified then every request matched

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpResponse": {
    "body": "some_response_body"
  }
}'
```

#### Match Request All Requests And Return UTF-16

If no request matcher is specified then every request matched

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpResponse": {
    "headers": {
      "content-type": [
        "text/plain; charset=utf-16"
      ]
    },
    "body": {
      "type": "BINARY",
      "base64Bytes": "/v9iEYv0Ti1W/Yvd"
    }
  }
}'
```

#### Match Request And Return UTF-16

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "method": "GET",
    "path": "/simple"
  },
  "httpResponse": {
    "body": {
      "type": "STRING",
      "string": "سلام",
      "contentType": "text/plain; charset=utf-8"
    }
  },
  "times": {
    "unlimited": true
  }
}'
```

#### Match Request All Requests And Return Simple Response With Plan Text Body

If no request matcher is specified then every request matched

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpResponse": {
    "headers": {
      "Content-Type": [
        "plain/text"
      ]
    },
    "body": "some_response_body"
  }
}'
```

#### Match Request All Requests And Return Response With Cookie

If no request matcher is specified then every request matched

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpResponse": {
    "headers": {
      "Content-Type": [
        "plain/text"
      ]
    },
    "cookies": {
      "Session": "97d43b1e-fe03-4855-926a-f448eddac32f"
    },
    "body": "some_response_body"
  }
}'
```

#### Match Request And Return Response With Status Code And Custom Reason Phrase

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "method": "POST",
    "path": "/some/path"
  },
  "httpResponse": {
    "statusCode": 418,
    "reasonPhrase": "I'm a teapot"
  }
}'
```

#### Match Request And Return Response With Binary PNG Body

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/ws/rest/user/[0-9]+/icon/[0-9]+\\.png"
  },
  "httpResponse": {
    "statusCode": 200,
    "headers": {
      "content-type": [
        "image/png"
      ],
      "content-disposition": [
        "form-data; name=\"test.png\"; filename=\"test.png\""
      ]
    },
    "body": {
      "type": "BINARY",
      "base64Bytes": " "
    }
  }
}'
```

#### Match Request And Return Response After Ten Second Delay

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpResponse": {
    "body": "some_response_body",
    "delay": {
      "timeUnit": "SECONDS",
      "value": 10
    }
  }
}'
```

#### Match Request And Return Response With Connection Options To Suppress Headers

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpResponse": {
    "body": "some_response_body",
    "connectionOptions": {
      "suppressContentLengthHeader": true,
      "suppressConnectionHeader": true
    }
  }
}'
```

#### Match Request And Return Response With Connection Options To Override Headers

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpResponse": {
    "body": "some_response_body",
    "connectionOptions": {
      "contentLengthHeaderOverride": 10,
      "keepAliveOverride": false
    }
  }
}'
```

#### Match Request And Return Response With Connection Options To Close Socket

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpResponse": {
    "body": "some_response_body",
    "connectionOptions": {
      "closeSocket": true
    }
  }
}'
```

#### Javascript Templated Response

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpResponseTemplate": {
    "template": "return {'statusCode': 200,'cookies': {'session': request.headers['session-id'][0]},'headers': {'Date': Date()}, 'body': {method: request.method, path: request.path, body: request.body}};",
    "templateType": "JAVASCRIPT"
  }
}'
```

#### Javascript Templated Response With Delay

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpResponseTemplate": {
    "template": "if (request.method === 'POST' && request.path === '/somePath') { return {'statusCode': 200, 'body': {name: 'value'}}; } else { return {'statusCode': 406, 'body': request.body};}",
    "templateType": "JAVASCRIPT",
    "delay": {
      "timeUnit": "MINUTES",
      "value": 2
    }
  }
}'
```

#### Velocity Templated Response

```bash
curl -X PUT 'localhost:1080/mockserver/expectation' \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpResponseTemplate": {
    "template": "{\"statusCode\": 200,\"cookies\": {\"session\": \"$!request.headers['Session-Id'][0]\" },\"headers\": {\"Client-User-Agent\": [ \"$!request.headers['User-Agent'][0]\" ] },\"body\": $!request.body}",
    "templateType": "VELOCITY"
  }
}'
```

#### Retrieve All Active Expectations

```bash
curl -X PUT "http://localhost:1080/mockserver/retrieve?type=ACTIVE_EXPECTATIONS"
```

#### Retrieve Active Expectations In Json Filtered By Request Matcher

/mockserver/retrieve?type=ACTIVE_EXPECTATIONS&format=JSON

```bash
curl -X PUT "http://localhost:1080/mockserver/retrieve?type=ACTIVE_EXPECTATIONS&format=JSON" \
-d '{
    "path": "/some/path",
    "method": "POST"
}'
```

#### Retrieve All Recorded Expectations

```bash
curl -X PUT "http://localhost:1080/mockserver/retrieve?type=RECORDED_EXPECTATIONS"
```

#### Retrieve Recorded Expectations In Json Filtered By Request Matcher

```bash
curl -X PUT "http://localhost:1080/mockserver/retrieve?type=RECORDED_EXPECTATIONS&format=JSON" \
-d '{
    "path": "/some/path",
    "method": "POST"
}'
```

#### Retrieve All Recorded Requests

```bash
curl -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUESTS"
```

#### Retrieve Recorded Requests In Json Filtered By Request Matcher

```bash
curl -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUESTS&format=JSON" \
-d '{
    "path": "/some/path",
    "method": "POST"
}'
```

#### Retrieve All Recorded Requests And There Responses

```bash
curl -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUEST_RESPONSES"
```

#### Retrieve Recorded Requests And There Responses In Json Filtered By Request Matcher

```bash
curl -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUEST_RESPONSES&format=JSON" \
-d '{
    "path": "/some/path",
    "method": "POST"
}'
```
