0

I wanna make a server-side database query based on the following data from the client:

const passengers = {
  adults: 5,
  teens: 1,
  kids: 2,
  babies: 3,
  pets: 0
};

What I know

I'm aware that I can send all the properties as individual query parameters, but I'm going to be sending some other ones and I'm interested in:

  • Grouping some of the data I send.
  • The capability of sending more complex objects with nested properties.

I'm also aware that I can switch to a POST request that accepts a JSON body, but I was willing to stick with GET since the response is a list of the queried entity and I think that GET suits better that concept as POST is rather meant for creating elements.

Is using POST the only option or can I solve this with a GET request?

Desko27
  • 1,498
  • 10
  • 10
  • 2
    Possible duplicate of [HTTP GET with request body](https://stackoverflow.com/questions/978061/http-get-with-request-body) – Ivan Vasiljevic Nov 17 '17 at 10:00
  • 1
    There's nothing stopping you from putting a json string in the qurey parameters, not ideal but I think it will be more reliable than adding a body to a get request – Sello Mkantjwa Nov 17 '17 at 10:08
  • @IvanVasiljevic Thank you for pointing out that question, I can see why you mention it. However, I'm aware that sending a body over a GET request is out of the HTTP standard. I'm asking for an alternative to it. – Desko27 Nov 17 '17 at 10:09
  • @SelloMkantjwa Hmm that seems the way to go, if no better one shows up that could be the right answer for me. Thank you. – Desko27 Nov 17 '17 at 10:12

1 Answers1

1

There's nothing stopping you from putting a json string in the query parameters, not ideal but I think it will be more reliable than adding a body to a get request

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sello Mkantjwa
  • 1,798
  • 1
  • 20
  • 36