Match on request headers
I was just thinking of mocking different responses, and one idea was to just throw in a Prefer header: https://tools.ietf.org/html/draft-snell-http-prefer-15
> Prefer: status=200
> Prefer: status=404
If not Prefer request header was sent, or not match was found, just take the first mocked response.
Could maybe be an extension to your latest addition "multiple actions on a single resource"
PS: I guess for now, the only way to do this is add a query param &_preferStatus=404 ?
You can now force Apiary mock server to return a particular Response of your choice.
Perform a request with the header “Preferred:status=304” (without the quotes) and the finest Response with status code 304 (if defined) is returned.
Its not Preferred:status=304, it should be Prefer:status=304
Jordan Hornblow commented
Agree with Rob! Need to be able to specify which response code pls.
Any progress on preferring specific headers or can you still only prefer a status? I'm trying to find a way to pick which 200 gets returned when I have multiple 200 responses defined
AdminJakub Korál (Developer, apiary.io) commented
It might get an update in near future. Maybe something like this:
"Preferred: Any-Header-Name=Value; Another_Header_Name=Some-Value" ...
But maybe it will become too complex then.
+1 for matching on Request Headers.. I want to return a different response according to what "Range" request header value is received.
AdminLukas Linhart (Admin, apiary.io) commented
Thanks for your input, Chuck. Great point.
Chuck Clark commented
I'd like to have something similar. We have a private API (meaning we control the clients). With each release of the mobile app we update the User-Agent header to reflect the version of the app. We had an instance where a bug on the client meant we did not want it to be able to make certain requests any longer.
For instance I think the API Blueprint would look something like this:
Get status of the ability to sync
> User-Agent: FooClient/1.9
> User-Agent: FooClient/2.0
It would be great to have this as mocked endpoint that I could use to regression test my clients against.
What about testing multiple response types, i.e. XML and JSON? You would indicate which type through the HTTP Accept header.
AdminZ (Admin, apiary.io) commented
I really love this idea Andrei! Would be blast for testing clients!