News for hackers. Stuff that matters.
Re:Most RESTful APIs Aren't RESTful by meehai on Wednesday July 09, 2025 @09:29AM (#44509834)
the last point got me.

How can you idiomatically do a read only request with complex filters? For me both PUT and POST are "writable" operations, while "GET" are assumed to be read only. However, if you need to encode the state of the UI (filters or whatnot), it's preferred to use JSON rather than query params (which have length limitations).

So ... how does one do it?

Re:Most RESTful APIs Aren't RESTful by kevindamm on Wednesday July 09, 2025 @10:05AM (#44510204)
One uses POST and recognizes that REST doesn't have to be so prescriptive.

The part of REST to focus on here is that the response from earlier well-formed requests will include all the forms (and possibly scripts) that allow for the client to make additional well-formed requests. If the complex filters are able to be made with a resource representation or from the root index, regardless of HTTP methods used, I think it should still count as REST (granted, HATEOAS is only part of REST but I think it should be a deciding part here).

When you factor in the effects of caching by intermediate proxy servers, you may find yourself adapting any search-like method to POST regardless, or at least GET with params, but you don't always want to, or can't, put the entire formdata in params.

Plus, with the vagaries of CSRF protections, per-user rate-limiting and access restrictions, etc.,, your GET is likely to turn into a POST for anything non-trivial. I wouldn't advise trying for pure REST-ful on the merits of its purity.

Re:Most RESTful APIs Aren't RESTful by rswail on Wednesday July 09, 2025 @11:50AM (#44511547)
HTML FORMs are limited to www-form-encoded or multipart. The length or the queries on a GET with a FORM is limited by intermediaries that shouldn't be limiting it. But that's reality.

Do a POST of a query document/media type that returns a "Location" that contains the query resource that the server created as well as the data (or some of it) with appropriate link elements to drive the client to receive the remainder of the query.

In this case, the POST is "writing" a query resource to the server and the server is dealing with that query resource and returning the resulting information.

Re:Most RESTful APIs Aren't RESTful by shagie on Wednesday July 09, 2025 @09:34AM (#44509882)
POST the filter, get a response back with the query to follow up with for the individual resources.

    POST /complex
    
    value1=something
    value2=else
which then responds with

    201 Created
    Location https://example.com/complex/53301a34-92d3-447d-ac98-964e9a8b3989
And then you can make GET request calls against that resource.

It adds in some data expiration problems to be solved, but its reasonably RESTful.

Re:Most RESTful APIs Aren't RESTful by blueflow on Wednesday July 09, 2025 @09:53AM (#44510066)
This has RESTful aesthetics but it is a bit unpractical if a read-only query changes state on the server, as in creating the uuid-referenced resource.
Re:Most RESTful APIs Aren't RESTful by rswail on Wednesday July 09, 2025 @11:55AM (#44511618)
There's no requirement in HTTP (or REST) to either create a resource or return a Location header.

For the purposes of caching etc, it's useful to have one, as well as cache controls for the query results, and there can be links in the result relative to the Location (eg a link href of "next" is relative to the Location).

Re:Most RESTful APIs Aren't RESTful by koolala on Wednesday July 09, 2025 @09:49AM (#44510030)
Isn't this twice as slow? If your server was far away it would double load times?
Re:Most RESTful APIs Aren't RESTful by ivan_gammel on Wednesday July 09, 2025 @10:01AM (#44510158)
The response to POST can return everything you need. The Location header that you receive with it will contain permanent link for making the same search request again via GET.

Pros: no practical limit on query size. Cons: permalink is not user-friendly - you cannot figure out what filters are applied without making the request.

Re:Most RESTful APIs Aren't RESTful by sahruum9 on Wednesday July 09, 2025 @09:51AM (#44510049)
There was a proposal[1] a while back to define a new SEARCH verb that was basically just a GET with a body for this exact purpose.

[1]: https://www.ietf.org/archive/id/draft-ietf-httpbis-safe-meth...

Re:Most RESTful APIs Aren't RESTful by Timon3 on Wednesday July 09, 2025 @10:18AM (#44510366)
Similarly, a more recent proposal for a new QUERY verb: https://httpwg.org/http-extensions/draft-ietf-httpbis-safe-m...
Re:Most RESTful APIs Aren't RESTful by ivan_gammel on Wednesday July 09, 2025 @09:55AM (#44510084)
If you really want this idiomatically correct, put the data in JSON or other suitable format, zip it and encode in Base64 to pass via GET as a single parameter. To hit the browser limits you will need so big query that you may hit UX constraints earlier in many cases (2048 bytes is 50+ UUIDs or 100+ polygon points etc).

Pros: the search query is a link that can be shared, the result can be cached. Cons: harder to debug, may not work in some cases due to URI length limits.

Re:Most RESTful APIs Aren't RESTful by dolmen on Wednesday July 16, 2025 @10:32AM (#44582801)
Cons: not postman or cURL friendly.
Re:Most RESTful APIs Aren't RESTful by cjpearson on Wednesday July 09, 2025 @11:43AM (#44511456)
Soon, hopefully, QUERY will save us all. In the meantime, simply using POST is fine.

I've also seen solutions where you POST the filter config, then reference the returned filter ID in the GET request, but that often seems like overkill even if it adds some benefits.

Re:Most RESTful APIs Aren't RESTful by 9rx on Wednesday July 09, 2025 @04:54PM (#44514639)
"Filters" suggests that you are trying to query. So, QUERY, perhaps? https://httpwg.org/http-extensions/draft-ietf-httpbis-safe-m...

Or stop worrying and just use POST. The computer isn't going to care.