Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Complex filter queries in a REST API

by bliako (Monsignor)
on Mar 25, 2021 at 11:25 UTC ( [id://11130317]=note: print w/replies, xml ) Need Help??


in reply to Complex filter queries in a REST API

it's been a while since I quit using GET params for anything complex. I now usually POST a JSON string.

So, why force a complex DB query into a GET params string when you can send your query as a JSON string to be converted to a Perl data structure and then directly imported into SQL::Abstract. There exists SQL::Abstract::FromQuery for even simpler data format.

bw, bliako

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

Replies are listed 'Best First'.
Re^2: Complex filter queries in a REST API
by hippo (Bishop) on Mar 25, 2021 at 12:23 UTC

    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.


    🦛

      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

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11130317]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-04-25 11:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found