mountebank icon indicating copy to clipboard operation
mountebank copied to clipboard

:zap: Expose `request` data directly into imposters

Open x80486 opened this issue 2 years ago • 0 comments

I've been testing Mountebank and I stumble with some things I've already seen implemented in other software of the same nature. For instance, let's take a look at this imposter:

{
  "name": "characters-api.create",
  "port": 8090,
  "protocol": "http",
  "stubs": [
    {
      "predicates": [
        {
          "equals": {
            "headers": {
              "Accept": "application/json",
              "Content-Type": "application/json"
            },
            "method": "POST",
            "path": "/api/characters"
          }
        }
      ],
      "responses": [
        {
          "is": {
            "headers": {
              "Location": "<% ${request.uri.path}/${uuid.generate} %>"
            },
            "statusCode": 201
          }
        }
      ]
    }
  ]
}

At that point, all I'm interested is in grabbing the URI that was used (from the request), generate some data on the fly (a UUID) and send the response back.

Is it possible to accomplish that in the way I'm describing it, or is it required to use behaviors.decorate / inject?

x80486 avatar Mar 31 '22 14:03 x80486