2 Replies - 268 Views - Last Post: 13 April 2013 - 03:49 PM

#1 Maya1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-April 13

Looking for advices for REST API

Posted 13 April 2013 - 12:26 PM

I'm working on a web application and designing an API as REST API (However, sticking to the REST rules exactly isn't mandatory).

The application has a customers list.

My questions:

1. How to deal with several GET methods for one resource? For example, I have the address api/customers, and the API clients want to receive different information from it every time. A regular GET request to api/customers will get the customers list, but what if they want other information? List name, list status...?

2. Which HTTP method should I use for advancing to the next customer? Since this action is not idempotent, I can't use PUT. Would POST be a good way to do it? Or PATCH? Should it be in a different address? Such as api/customers/next, and then a POST method to this address will advance to the next customer?

Thank you

Is This A Good Question/Topic? 0
  • +

Replies To: Looking for advices for REST API

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: Looking for advices for REST API

Posted 13 April 2013 - 01:45 PM

There are different schools of thought on this, so do some more research and get a feel for those.

1. A GET of a resource without an ID should get a list of those resources. A GET of a resource with an ID should get the resource with that ID. What the API user does with that info is up to them; you might let them filter it.

2. If you follow the above, you're still talking about a GET just with a different ID.

GET : Retrieve data
POST : Add data
PUT : Edit data
DELETE : Delete data
Was This Post Helpful? 0
  • +
  • -

#3 Maya1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-April 13

Re: Looking for advices for REST API

Posted 13 April 2013 - 03:49 PM

Thanks for the answer :)

View PostJackOfAllTrades, on 13 April 2013 - 01:45 PM, said:

There are different schools of thought on this, so do some more research and get a feel for those.

1. A GET of a resource without an ID should get a list of those resources. A GET of a resource with an ID should get the resource with that ID. What the API user does with that info is up to them; you might let them filter it.


But calling api/customers with GET will call extra functions that the API user doesn't need, if he only wants the name/status of the list.

Quote

2. If you follow the above, you're still talking about a GET just with a different ID.

GET : Retrieve data
POST : Add data
PUT : Edit data
DELETE : Delete data


The API user doesn't know the current ID when he wants to call "next". The request is supposed to be made on api/customers/next. It's like x++, an increment. Therefore I can't use GET...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1