3

Given a URL structure like this:

 GET           /user/giftcards/:id

When returning list with all my giftcard:

 GET           /user/giftcards

And here comes my questions, what is best practice for URL structure if I also want to return subsections of the giftcards, like received or sent?

Today I do this (but I know its wrong since the URL should represents the noun / resource (here: giftcard)

 GET           /user/giftcardsreceived
 GET           /user/giftcardssent

The way I see it there are two "better" solutions:

 GET           /user/giftcards/received
 GET           /user/giftcards/sent

or

 GET           /user/giftcards?filter=received
 GET           /user/giftcards?filter=sent

Im leaning towards the request param solution with filtering since the other solution could potentially conflict with the GET based on id.

Any pointing in right direction appreciated.

Thomas Vervik
  • 3,615
  • 9
  • 32
  • 58
  • possible duplicate of [REST API Best practices: Where to put parameters?](http://stackoverflow.com/questions/4024271/rest-api-best-practices-where-to-put-parameters) – Makoto Feb 23 '15 at 23:30
  • Thanks, didnt fint it when I searched, good one – Thomas Vervik Feb 24 '15 at 00:27

2 Answers2

2

Since this corresponds to a sub list of elements, this should be served by the same resource that addresses such list of elements. So using query parameters would be better in my point of view.

The following link could give you additional hints:

Hope it helps you, Thierry

Thierry Templier
  • 182,931
  • 35
  • 372
  • 339
1

I personally prefer the query param style as the status is usually a property of the resource rather than a brand new resource itself.

Check out Brian Mulloy's presentation on api design. It's as good a place to start as any

stringy05
  • 4,973
  • 23
  • 30