9

I'm implementing a RESTful API to display search results based on a huge number of parameters. There are so many of them at this point that using a HTTP GET method feels quite cumbersome.

I was wondering whether it is okay to use a HTTP POST method to POST these parameters all at once at every request in exchange of a result set instead of bothering with so many GET parameters.

Some of these GET requests are even blocked by certain firewalls for being too long.

Comments
  • 4
    Seems fine to me, makes reading it easier as well
  • 2
    Well, one would use a GET request for fetching search results. You could however allow a POST to an endpoint like /search, that would return a token like /search/a1b2c3d4, which in turn could be used to get the search results, I guess?
  • 5
    Honestly? REST is a broken fucking mess, and the fact there are so many questions on it all over the place speaks to that.

    For something that is supposed to be stateless, the solution of posting a search “request” and getting a resource identifier for the results which you then fetch is logically sound, but in practice just a nightmare, not least because of the introduction of additional reliance on the data store.

    I’d honestly say to hell with it, accept a post request, and take a JSON payload describing the search (parameters and all) and just spit back the response.
  • 1
    If you have time maybe take a look at graphql. Especially if you have many parameters it might be the right solution for you
  • 0
    I let loopback.io handle some of that. Soap/xml was way too heavy. Rest is way to light / under-developed.

    I’m not a fan of sql-like url querying. Might as well pass actual sql. And rely on a sanitizing library. But that is just me.
  • 0
    @TempestasLudi you can do something like this. UpdateStatus returns Json response to the client. Did this for an interview.
  • 0
    @TRex Okay, couple of questions:
    - Why did you tag me in it? It does not seem to specifically concern me;
    - What language is this? I don't really recognize it;
    - Why did you post it? OP asked whether it would be acceptable to fetch stuff via a POST request, not how one would implement a backend that would support it. He implies that he can do the actual coding of the frontend/backend himself ;-)
  • 1
    @TempestasLudi tagged you by mistake 😂 It's java, yeah it's acceptable to fetch data by post(do authentication request ring a bell)
  • 0
    @TRex Authentication requests (for an authentication token) is officially the act of creating a token on the server via POST and getting its location in return...
  • 1
    GET URL has character limits. So yeah, if it's really long, you should go with POST.
Your Job Suck?
Get a Better Job
Add Comment