mockify
mockify copied to clipboard
Add response correlation
Hi
First thanks for this mock solution 👍
I've need to add correlation between request and response. So basically I replace mux vars by their value in the response. Here's a simple example from your routes.json:
{
"routes": [
{
"path": "/helloworld/{key}",
"methods": [
"GET",
"POST"
],
"responses": [
{
"methods": [
"GET",
"POST"
],
"uri": "/helloworld/foo",
"GET": {
"statusCode": 200,
"body": {
"message": "[GET] Hello {key}!"
},
"headers": {
"Content-Type": "application/json"
}
},
"POST": {
"statusCode": 200,
"body": {
"message": "[POST] Hello {key}!"
},
"headers": {
"Content-Type": "application/json"
}
},
"PUT": {},
"DELETE": {}
}
]
}
]
}
And so on, {key} in the response content is replaced by the request url parameter:
curl -X GET \
http://localhost:8001/helloworld/foo
{"message":"[GET] Hello foo!"}
What do you think about it ?
You’re welcome! Thanks for contributing!
Sorry I’m not sure what you mean. This functionality already exists. The routes path maps to the responses uri. So based on the sample routes file, if you did a request to helloworld/bar, you would get an error because there is no response mapping uri.
Oh! Is there's any solution to add correlation between request and response so ? Like re-using route pattern in responses node ?
Oh i think I get what you are saying now. So for clarification, if the route path is /helloworld/{foo}, you are adding functionality to map a response uri /helloworld/{foo}. If you were to also add a response uri /helloworld/{baz} then you would need to add a route path for that response.
Is that a correct explanation of the new feature?