I don't think GETs should ever change state. I'm fine with all other operations being POSTs though. If nothing else it provides compatibility with clients that don't support all the HTTP verbs (yes there are some)
How do you manage big queries with GET?
Do you really know why you prefer REST over RPC?
11–20 of 124 posts
Re: Do you really know why you prefer REST over RPC?
#12> DELETE /users/1234
No! It would be
DELETE /sessions/12345
or possibly DELETE /users/1234/session
or even DELETE /users/1234/sessions/3
in the case a user can have more than one concurrent different sessions (this is actually a fairly common case for the application we do were I work. We don't use http for this though).Unless you actually want to permanently stop the user from using the system, in which case
DELETE /users/1234
would be the perfectly obvious choice.Re: Do you really know why you prefer REST over RPC?
#13RPC leads to fragile protocols. Adding arguments to a procedure or adding properties to a result can often break clients and in practice you update systems lock step.
HTTP can gracefully handle different API version requests to the same resource. REST clients are encouraged to take only what they need from the representation.
Also, I strongly disagree with the Totaling points section. Seems too "nice" to both sides.
Re: Do you really know why you prefer REST over RPC?
#141. Non-authenticated users can create users, and see a list of users with details that are public.
2. Authenticated users can view their own public and private details and have read/write access to most fields except is_staff.
3. Staff users have full permissions for users that belong to the country they are managing.
4. Superusers have access to everything.
Without the benefit of DSLs this would take hours to write all the if/else statements and unit test them. It would be a nightmare to do the same for all your endpoints. I assume you can write some abstraction functions to use for all your RPC endpoints but it'd be easier to reuse a library from past projects that had the same REST API design.
Example:
Row level:
permission_classes = [
Or(And(Or(IsOwner('id'), IsStaff), IsUpdateOnly),
And(AllowAny, IsReadOnly),
And(AllowAny, IsCreateOnly))]
Field level: is_public = And(IsActive, Is('is_public', True))
fields = {
'display_name': [],
('is_active', 'password', 'email'): [
Or(is_staff_or_owner, IsCreateOnly)
],
('full_name', 'slug',): [
Or(is_staff_or_owner, is_public, IsCreateOnly)
]
}Re: Do you really know why you prefer REST over RPC?
#15I don't think GETs should ever change state. I'm fine with all other operations being POSTs though. If nothing else it provides compatibility with clients that don't support all the HTTP verbs (yes there are some)
How do you manage big queries with GET?
Practically speaking, I don't know if I've ever had a querystring that was effectively too large, busting some browser-determined limit. If you did, you might as well use a POST instead of GET, because the request is unlikely to be cacheable (I'm assuming the reason its such a large string is that you're serializing a large form of values or using the querystring to persist state in some way [protip: this is a bad idea]), which is the main reason to prefer GET for the request. POST (according to HTTP semantics, may have side effects, but is not required to have side effects).
IMHO, the choice between HTTP verbs beyond GET vs everything else is mostly bikeshedding. As a convention its fine, but there aren't a lot of pragmatic technical reasons to go with one over the other (referring to PUT vs PATCH vs POST), despite the HTTP semantics.
Re: Do you really know why you prefer REST over RPC?
#16http://illuminatedcomputing.com/posts/2011/07/restless-doubt...
Basically, after form submit errors your location bar still says /widgets or /widgets/1 rather than /widgets/new or /widgets/1/edit, so bookmarking that page, or "like"ing it, or Ctrl-L + ing are all broken. I'd much prefer a redirect back to the correct URL.
Also the distinction between "create" and "update" can break the back button, if the user creates something, then clicks back to edit their submission (because submitting a second time will create a second thing, not update their original thing). That's not Rails so much as REST in general.
Re: Do you really know why you prefer REST over RPC?
#17Earlier quoted context omitted.
How do you manage big queries with GET?
By query, are you referring to the querystring/url size? Practically speaking, I don't know if I've ever had a querystring that was effectively too large, busting some browser-determined limit. If you did, you might as well use a POST instead of GET, because the request is unlikely to be cacheable (I'm assuming the reason its such a large string is that you're serializing a large form of values or using the querystri…
Re: Do you really know why you prefer REST over RPC?
#18We had a couple of problems with GET requests: all of our data ended up in the url (we have too much info that has to be passed, we stopped working on some browsers), and the data returned could be cached (which is a HUGE problem for us).
Now, POSTs can also be cached, but there are easy ways around it...you can do the same thing with a GET, but that means adding more information to the url.
Anyway, one we got to the point of forgoing all GET requests, we ended up just doing everything with a POST for simplicity.
Re: Do you really know why you prefer REST over RPC?
#19I might be behind on state of the art these days...but my current api has no GET requests, everything is a POST. So in that term, we are not restful. We had a couple of problems with GET requests: all of our data ended up in the url (we have too much info that has to be passed, we stopped working on some browsers), and the data returned could be cached (which is a HUGE problem for us). Now, POSTs can also be cached,…
Re: Do you really know why you prefer REST over RPC?
#20GET /api/resource
POST /api/resource/action
Where 'action' is something a bit more descriptive than 'PUT' or 'DELETE' or whatever. Kind of like an object-oriented api... I'm still always dealing with resources, but I have custom actions for specific use cases.