by fzilla · 10y ago · 0 comments
This isn't how REST is supposed to work
Fielding's dissertation isn't a spec, which pretty much means everyone can come up with their own little slice of how it should be done and then say they're doing it right.
The true rule of REST: whoever is blogging/commenting about it at the time is doing REST right, all others are confused and incorrect.
Conventionally that is true and it certainly reduces friction in your API by adhering to common conventions.
In the case of closing an account, it depends on what actually happens when you do so, but I would normally have a "status" attribute and use PATCH to update that.
PATCH /users/123
[{ "op": "replace", "path": "/accounts/12345/status", "value": "closed" }]
I personally think that's less readable than the original, but I agree that it seems to more closely fit the REST standard.With the deposit, I don't really understand what's changed here from the original. To me, it just looks like deposit has been pluralised, and everything else is the same:
POST /account/12345/deposits
amount=10Regarding the deposits, the difference is that 'deposits' is a collection of deposit resources vs 'deposit' as a verb. I think in this case it makes a lot of sense to do it that way, as you can then GET /account/12345/deposits and see all the deposits ever made.
POST /transfer
from_account_id=12345&to_account_id=67890&amount=10
Perhaps I've misunderstood your comment, as I don't really understand why this is better than the original: POST /accounts/12345/transfer
to_account_id=67890&amount=10
or even: POST /accounts/12345/withdraw
amount=10The key point though is that 'transfer' is the resource to perform all three of the original deposit/withdrawal/transfer actions.