in reply to Re: Complex filter queries in a REST API
in thread Complex filter queries in a REST API

REST mandates the use of GET for an operation which purely retrieves information. If you are using a POST just to retrieve information then your API is not REST.


🦛

  • Comment on Re^2: Complex filter queries in a REST API

Replies are listed 'Best First'.
Re^3: Complex filter queries in a REST API
by bliako (Abbot) on Mar 25, 2021 at 15:08 UTC

    Good point, but JSON can be sent also by GET (URI encoded and paying attention to the max length). On the other hand, sending JSON can confuse or blind server-side caching if you ever need this with live-db queries.

      Thanks for this suggestion. I was clearly overthinking the situation.

      I need to comply to the REST style and must use a GET request, but my cases are small enough that using a JSON string should be possible. And SQL abstract is already familiar, so implementation should not be an issue. I will test this approach.

      Kind regards

        Just to clarify (and to others): I merely said that *I* use POST. Nothing stops you using GET+JSON but the max URI length.

        In my first post I deleted accidentally a serious caveat: that with a SQL::Abstract-style query you are exposing the structure of your DB to the client unless you alias field and table names.

        bw, bliako

Re^3: Complex filter queries in a REST API
by Anonymous Monk on Mar 25, 2021 at 14:10 UTC
    Maybe so, but Baiko's point still holds. GET-parameters can quickly become unwieldy, whereas a JSON payload can be anything you want. It really isn't a matter of "doctrine." It's what works best for you.