gstroup / apimocker

node.js module to run a simple http server for mock service responses.
MIT License
280 stars 81 forks source link

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

Open EarthyOrange opened 4 years ago

EarthyOrange commented 4 years ago

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 commented 4 years ago

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.