Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change response json after proxy #291

Open
fabsimilian opened this issue Feb 16, 2021 · 4 comments
Open

Change response json after proxy #291

fabsimilian opened this issue Feb 16, 2021 · 4 comments

Comments

@fabsimilian
Copy link

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
Copy link
Owner

Why do you need to change the response value?

@fabsimilian
Copy link
Author

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
Copy link
Owner

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

@dreamhead
Copy link
Owner

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"
        }
      }
    }
  } 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants