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

Add response correlation #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

ScullWM
Copy link

@ScullWM ScullWM commented Oct 3, 2018

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 ?

@brianmoran
Copy link
Owner

brianmoran commented Oct 3, 2018

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.

@ScullWM
Copy link
Author

ScullWM commented Oct 8, 2018

Oh! Is there's any solution to add correlation between request and response so ? Like re-using route pattern in responses node ?

@brianmoran
Copy link
Owner

brianmoran commented Oct 8, 2018

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?

@p4tin p4tin closed this Sep 15, 2019
@p4tin p4tin reopened this Sep 15, 2019
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

Successfully merging this pull request may close these issues.

3 participants