For a while I was (wrongly) thinking that a RESTful API just exposed CRUD operation to persisted entities for a web application. When you code something up in "the real world" you soon find out that this is not enough. For example, a bank account transfer doesn't have to be a persisted entity. It could be a transient resource where you POST
to /transfers/
and in the payload you specify the details:
{"accountToCredit":1234, "accountToDebit":5678, "amount":10}
Using POST
here makes sense because it changes the state on the server ($10 moves from one account to another every time this POST
occurs).
What should happen in the case where it doesn't affect the server? The simple first answer would be to use GET
. For example, you want to get a list of savings and checking accounts that have less than $100. You would then call something like GET
to /accounts/searchResults?minBalance=0&maxBalance=100
. What happens though if your search parameter need to use complex objects that wouldn't fit in the maximum length of a GET
request.
My first thought was to use POST
, but after thinking about it some more it should probably be a PUT
since it isn't changing the state of the server, but from my (limited) understanding I always though of PUT
as updating a resource and POST
as creating a resource (like creating this search results). So which should be used in this case?
I found the following links which provide some information but it wasn't clear to me what should be used in the different cases:
Transient REST Representations