1

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?

Jacob
  • 14,463
  • 65
  • 207
  • 320

2 Answers2

1

There is a doc how to handle it; basically, you need to have separate resources for separate payloads, as there is currently no way to "bind" URL argument into payload.

Almad
  • 5,753
  • 7
  • 35
  • 53
  • Hi Almad, Can you please provide an example? I am struggling to find the right answer to implement this. Thank you! – MeV Jun 18 '15 at 11:26
1

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

Community
  • 1
  • 1
MeV
  • 3,761
  • 11
  • 45
  • 78