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

Get json response according to uri parameter value #48

Open
suleymanccelik opened this issue Apr 6, 2015 · 14 comments
Open

Get json response according to uri parameter value #48

suleymanccelik opened this issue Apr 6, 2015 · 14 comments

Comments

@suleymanccelik
Copy link

Hi everyone,

How can I achieve to get json response according to uri parameter value? If p is equal to Y, I want to get first json body. But there is no p field in json body. If p is equal to X, I want to get second json body. I am using drakov as mock server. When I start drakov mock server, Both localhost:3000/api.php?p=Y and localhost:3000/api.php?p=X returns first json body.

drakov url : https://www.npmjs.com/package/drakov

GET /api.php?p=Y

  • Response 200 (application/json)

    { 
        json body
    }
    

GET /api.php?p=X

  • Response 200 (application/json)

    {
         json body
    }
    
@yakovkhalinsky
Copy link
Contributor

Hi @suleymanccelik this is currently not possible.

Currently Drakov only looks at the key of the query parameter. This is however on our roadmap.

We did a refactor of our route handling a short time ago with the view of handling these situations better in the future.

I'll do a review of what we need to do to achieve responses based on particular query parameter values and update you in this issue in the next day or so 👍

@suleymanccelik
Copy link
Author

Thanks for reply @yakovkhalinsky . Looking forward this feature.

@onato
Copy link

onato commented Apr 8, 2015

I would also love to see this feature.

I would like to use it for mocking an API for UI testing and creating screenshots for the App Store.

@hendrikmaus
Copy link

+1 is there any way to help?

@yakovkhalinsky
Copy link
Contributor

The good news is, we are currently doing some work on how parameters are treated, so I would think we could do this sooner rather than later. Will keep this issue updated when we get closer to getting this feature into drakov. 👍

@hendrikmaus PR's are very welcome! Feel free to dive into the code and ask questions 👍

@hendrikmaus
Copy link

Is this supported by the official API blueprint specs?

@yakovkhalinsky
Copy link
Contributor

@hendrikmaus previous response was wrong ( my head was in another issue :) )

I don't believe this is in the spec as far as I know.

@groyoh
Copy link
Contributor

groyoh commented Aug 4, 2015

@hendrikmaus not in the specs but handled by Apiary AFAIK.

@hendrikmaus
Copy link

Nice. This is also really neat if you write blueprints to run through dredd for testing besides your main documentation.

@groyoh
Copy link
Contributor

groyoh commented Oct 24, 2015

@yakovkhalinsky this issue should be fixed by #87. I think you can close it now.

@IvBre
Copy link

IvBre commented Jan 26, 2016

@groyoh unfortunately the commit from #87 does not solve this issue. Drakov mock server still can't differentiate the requests with different value for the same query param, at least not using API blueprint file.
I guess until API Blueprint does not solve the issue of defining different param values for different response in one request (apiaryio/api-blueprint#58) then Drakov can't use that information in matching the requests. :(
Please let me know if I'm wrong.

@groyoh
Copy link
Contributor

groyoh commented Jan 27, 2016

@IvBre doing something like this works:

## Things [/api/query?param1=12345]

+ Parameters
    + param1 (string, `12345`) ... Parameter for the request

### Get with query parameter [GET]

+ Response 200 (application/json;charset=UTF-8)

    + Body

            {
               "id": "parameter1_12345"
            }

## Things [/api/query?param1=12346]

+ Parameters
    + param1 (string, `12346`) ... Parameter for the request

### Get with query parameter [GET]

+ Response 200 (application/json;charset=UTF-8)

    + Body

            {
               "id": "parameter1_12346"
            }

@IvBre
Copy link

IvBre commented Feb 1, 2016

@groyoh thank you for your suggestion, it seems that it works! Although Dredd is complaining that there is no {param1} defined in the URI template, but its not critical. Thank you!

@groyoh
Copy link
Contributor

groyoh commented Feb 1, 2016

@IvBre glad I was able to help. To be clear on this, you are right when saying that this is (was?) not within the specification, but since it worked on Apiary (not sure if it is still the case) I thought than adding it to drakov would be helpful as we also needed it.

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

No branches or pull requests

6 participants