1

As per REST framework, we can access resources using GET method, which is fine, if i know key my resource. For example, for getting transaction, if i pass transaction_id then i can get my resource for that transaction. But when i want to access all transactions between two dates, then how should i write my REST method using GET.

For getting transaciton of transaction_id : GET/transaction/id For getting transaction between two dates ???

Also if there are other conditions, i need to put like latest 10 transactions, oldest 10 transaction, then how should i write my URL, which is main key in REST.

I tried to look on google but not able to find a way which is completely RESTful and solve my queries, so posting my question here. I have clear understanding of POST and DELETE, but if i want to do same update using PUT for some resource based on condition, then how to do it?

Mitesh Sharma
  • 261
  • 4
  • 14
  • 1
    See this question: http://stackoverflow.com/questions/4024271/rest-api-best-practices-where-to-put-parameters – Sergey K May 27 '14 at 15:53
  • Thanks for pointing to right link. I can send filters with URL, so i need to handle all possible filter in one server call where i send GET result, right? or any other suggestion? – Mitesh Sharma May 27 '14 at 17:52
  • Yes, and the details of how you would do that depend on what backend framework you're using. – Sergey K May 27 '14 at 19:33

1 Answers1

0

There are collection and item resources in REST.

If you want to get a representation of an item, you usually use an unique identifier:

  • /books/123
  • /books/isbn:32t4gf3e45e67 (not a valid isbn)

or with template

  • `/books/{id}
  • /books/isbn:{isbn}

If you want to get a representation of a collection, or a reduced collection you use the unique identifier of the collection and add some filters to it:

  • /books/since:{fromDate}/to:{toDate}/
  • /books/?since="{fromDate}"&to="{toDate}"

the filters can go into the path or into the queryString part of the url.

In the response you should add links with these URLs (aka HATEOAS), which the REST clients can follow. You should use link relations, for example IANA link relations to describe those links, and linked data, for example schema.org or to describe the data in your representation. There are other vocabs as well, for example GoodRelations, and ofc. you can write your own vocab as well for your application.

inf3rno
  • 20,735
  • 9
  • 97
  • 171