> For the complete documentation index, see [llms.txt](https://httpstubhq.gitbook.io/httpstub/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://httpstubhq.gitbook.io/httpstub/stubs/pattern-matching.md).

# Pattern matching

A YAML file has one or more rules. The stub evaluates each `when` of all rules and returns the first matched `response`.

Here is the example of manifest as follows:

```yaml
rules:
  - when: params.order == 'desc'
    #first entry must contains info about request unit  
    request:
     path: /hello

    response:
      headers:
        content-type: application/json
      body: [3, 2, 1]

  - when: params.order == 'asc'
  
    response:
      headers:
        content-type: application/json
      body: [1, 2, 3]

  #presence check
  - when: params.containsKey('order')
  
    response:
      headers:
        content-type: application/json
      body: [4]

  #default response should be at the end of the list
  - response:
      headers:
        content-type: application/json
      body: [0]
```

The stub will return the following response on the request `GET /numbers?order=asc`

```
[1, 2, 3]
```

And on the request `GET /numbers?order=desc`

```
[3, 2, 1]
```

And on the request `GET /numbers?order`

```
[4]
```

And on the request `GET /numbers`

```
[0]
```

If the last entry is not defined, the stub will return a 404.
