I suggest you ...

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

GET /
> Prefer: status=200
< 200

GET /
> Prefer: status=404
< 404

If not Prefer request header was sent, or not match was found, just take the first mocked response.

Wdyt?
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 ?

27 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Andrei NeculauAndrei Neculau shared this idea  ·   ·  Admin →
    completed  ·  Jakub KorálJakub Korál responded  · 

    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.

    9 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Anonymous commented  · 

        Its not Preferred:status=304, it should be Prefer:status=304

      • Jordan HornblowJordan Hornblow commented  · 

        Agree with Rob! Need to be able to specify which response code pls.

      • RobRob commented  · 

        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

      • Jakub KorálAdminJakub 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.

      • LloydLloyd commented  · 

        +1 for matching on Request Headers.. I want to return a different response according to what "Range" request header value is received.

      • Chuck ClarkChuck 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:
        --
        Sync Resources
        --
        Get status of the ability to sync
        > User-Agent: FooClient/1.9
        GET /sync/status
        < 503
        +++++
        GET /sync/status
        > User-Agent: FooClient/2.0
        < 200

        It would be great to have this as mocked endpoint that I could use to regression test my clients against.

      • Anonymous commented  · 

        What about testing multiple response types, i.e. XML and JSON? You would indicate which type through the HTTP Accept header.

      Feedback and Knowledge Base