Search code examples
jsonapiary.ioapiary

APIARY Mock JSON Data for multiple Single Object


In my apiary, I have defined the following to retrieve one id when id is passed to A single Note object with all its details

{ "id": 2, "title": "Pick-up posters from post-office" }

http://private-22c1f-polpan.apiary-mock.com/notes/2

If I would like to pass another id by passing 3, how to define JSON entry in apiary?

{ "id": 2, "title": "Pick-up posters from post-office" }
{ "id": 3, "title": "third entry" }

However when I tried as

http://private-22c1f-polpan.apiary-mock.com/notes/3

it is not returning details for id 3.

How could I fix this?


Solution

  • As you can see from this question:

    Apiary.io - multiple responses (200) with different parameters

    It looks like Apiary Mock Server creates/generates only one URL for each resource and that URL parameters are not "tied up" with different responses. They might actually plan to do it in the future: https://github.com/apiaryio/api-blueprint/issues/58

    So, at the moment, I believe you have a simple solution to achieve what you need:

    Create different resources (one for each record), so each one will generate one URL.

    ## Note20 [/notes/20]
    
    ### Get notes20 [GET]
    
    + Response 200 (application/json)
    
            {
                "id" : 20,
                "name" : "note xxxx"
            } 
    
    ## Note21 [/notes/21]
    
    ### Get notes21 [GET]
    
    + Response 200 (application/json)
    
            {
                "id" : 21,
                "name" : "note yyyyy"
            } 
    

    Otherwise you can play with headers parameters, sent every time you call the URL, as explained in this link: http://support.apiary.io/knowledgebase/articles/117119-handling-multiple-actions-on-a-single-resource but I don't find it good.

    I don't have other solutions at the moment. Hope this helps you