No data mutations are assumed, an array is needed to get some information from the database on the массиву c ID ( for example, Long type , 1-2k in size ).

On the one hand, this is by all indications GET, and on the other hand, there is too much fuss and restrictions when parsing on the server side, as for me, POST looks much better for such tasks and I used it all my life. But today the "boss" said - do GET!

I need a firm and confident opinion, I will accept links to the gift where this issue is conceptually and theoretically disclosed.

For example, this information contains, personally for me, arguments in favor of POST.

  • Add the code you use, also indicate your library or framework, also an example of the data you are sending - MrFylypenko
  • The question is purely theoretical, and I do not think that there is a sense in at least some listings. sample data in question is available. - Vyacheslav Danshin
  • Need to send an array of strings or more complex structures? - Nofate
  • @Nofate for example Long, corrected the question. But I do not think that this is fundamentally within my question, I want to know conceptually how to do it correctly, if we simply request data and do not produce mutations, is it always GET, or always POST, or according to the situation? - Vyacheslav Danshin
  • one
    @papiroca has answered you in detail below. Depends on a situation. But usually GET. - Pavel Mayorov

2 answers 2

There is no reason why it would be impossible to send a GET array. Methods of transmission - the mass, the only question is what will be easier within the framework of libraries used by you personally.

 /api/getbyids/{id1}/{id2}/{id3}... /api/getbyids/{id1},{id2},{id3}... /api/getbyids?ids={id1},{id2},{id3}... /api/getbyids?id={id1}&id={id2}&id={id3}... /api/getbyids?id1={id1}&id2={id2}&id3={id3}... /api/getbyids?id[0]={id1}&id[1]={id2}&id[2]={id3}... /api/getbyids?id[]={id1}&id[]={id2}&id[]={id3}... 

The conceptual difference between GET and POST is that GET is a request for a resource that can be repeated, saved in a cache, remembered in a story, passed to a friend, and POST is a call to an action that is done once.

  • but there are restrictions on the length of the GET request, for example. And there is no reason why you can't write var someval = in js, but someVal looks better. - Vyacheslav Danshin
  • @papiroca It all depends on the length of the array - Pavel Mayorov
  • Well, let's say with an array length of 1-2k id, type 27354, for example - Vyacheslav Danshin
  • @papiroca well, most browsers can do that. If there is no middle proxy server for dinosaurs :) In the standard, there is no hard limit on the length of the URI. - Pavel Mayorov
  • github.com/dreikanter/paradigm.ru/blob/master/posts/… for example, information that can make you prefer POST - Vyacheslav Danshin

the article that dotted it, in my case

the most useful of it, perhaps enter image description here

source handynotes.ru

  • Not a bad algorithm. But I would also add a check whether “protection against a CSRF attack is necessary” (leads to POST) and removed the check about the user's benefit (it's easier to make GET than to think). - Pavel Mayorov