3 ms·
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
by ams6110 12y ago
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)
- k__ 12y agoHow do you manage big queries with GET?
- neverartful 12y agoWith a POST. The parent just pointed out that GET should not be used for updates. They didn't say that only GET should be used for retrievals.
- karmajunkie 12y agoBy 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 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.
- k__ 12y agoNo, it just was a very flexible data-retrieval API and the query strings just could get rather big.
- rojoca 12y agoUsually used for long running queries but sometimes appropriate for this problem is creating a "query" resource via POST after which you have a URI for the results: POST /queries {"query": "..."} 201 Created Location: /queries/1001 GET the results: GET /queries/1001 {"results": ...} You could optionally return results in the POST response too but I'm unsure whether that strictly conforms to the HTTP spec or not.
- marcosdumay 12y agoYes, just don't break HTTP. Don't let GETs edit data, if you use PUT make sure it's idempotent, DELETE looks dangerous, be sure not to waste that, and do whatever you want with POST.