apimocker icon indicating copy to clipboard operation
apimocker copied to clipboard

How do I return the request object as the response after adding one key to the request body?

Open EarthyOrange opened this issue 4 years ago • 1 comments

I have an endpoint that accepts a JSON object and responds with the same JSON object with the ID field updated with a unique value. So the rest of the request body is pretty much untouched.

My plan is to use a few fields from the request body for switch and assign an ID based on that. Since it can be a huge object, I want to avoid using templating to copy all the keys from the request body to the response body. Is there an easy way to do that?

Thanks!!

EarthyOrange avatar Oct 15 '20 16:10 EarthyOrange

I made some modifications in the code, that I have, to do this.

This is what I added to the switchResponses key in config.json.

{
  "$.path1value1": {
    "httpStatus": 200,
    "jsonPathUpdates": { "$.id": "ID" },
    "mockBody": "@@request"
}

And also added logic to consume this configuration. If this feature is ever officially added I will update the code that I have.

EarthyOrange avatar Nov 05 '20 00:11 EarthyOrange