dreamhead / moco

Easy Setup Stub Server
MIT License
4.36k stars 1.08k forks source link

Change response json after proxy #291

Open fabsimilian opened 3 years ago

fabsimilian commented 3 years ago

Currently I'm using moco with json. Is there a way to change a json property of a proxy response?

What I'm trying to achieve: Send a request to a different site, get the json response from that site and change a json property.

Example:

  {
    "request": {
      "uri": "/foo/bar"
    },
    "response": {
      "proxy": {
        "url": {
          "template": "http://another.site/${req.uri}"
        }
      }
    }
  } 

http://another.site/${req.uri} will return me a json like:

{
    "data" : {
        "id" : "12345",
        "foo" : "bar"
    }
}

And I want to change property foo to another value.

dreamhead commented 3 years ago

Why do you need to change the response value?

fabsimilian commented 3 years ago

We need to mock a state. We're developing a feature against a sandbox of an external provider. But there are not all possible states available in the sandbox environment. So we want to mock them for testing.

dreamhead commented 3 years ago

@fabsimilian Do you want to change "foo" with fixed value?

dreamhead commented 3 years ago

There is no current solution, but I'm trying to figure out a possible solution.

For example, configuration like the following:

{
    "request": {
      "uri": "/foo/bar"
    },
    "response": {
      "proxy": {
        "url": {
          "template": "http://another.site/${req.uri}"
        },
        "modifier": {
          "key" : {
            "jsonPath": "$.data.foo"
          },
          "value": "fixed"
        }
      }
    }
  }