Put many request parameters with a GET request in the REST API

Is it good to use many request parameters with a GET request in the REST API?

I went through a couple of sites and tried to get a standard way to execute a GET URI with parameter implementation.

Here's what I'm trying to achieve: search for all users having provided all the search criteria .

Search criteria are similar to companyID , sections , offset , limit , orderby , filter .

According to basic GET standards, a request cannot have a request body or payload .

Would there be a good way to make a GET request and put all parameters behind ? in the request url, something like this:

GET http://localhost:8080/api/users?companyId=qwerty§ions=hr&offset=0&limit=20&oorderby=asc&filter=^[sSmM]

I thought to make a PUT or POST and send all this data to the payload and implement the code to return the desired answer, i.e. a list of users.

If I do this, I will change the default behavior of HTTP methods .

Can you send me a way out of the situation. Thanks.

+4
source share
3 answers

I think it doesn't matter how many parameters you enter in the GET request. The purpose of the request POST or PUT is not to your URL was clean, but in order to hide the structure of REST.

raw definition of GET, POST, and PUT

  • GET : get resource from your server
  • POST : create a resource on your server.
  • PUT : update the resource on your server.
+3
source

In fact, you can pass the request body with the GET request. It is just not very common. JQuery supports this on the browser side and on the REST API, for example, for example, the elastic search API. They have a nice dsl json request, and you can use a GET request for them. Since some HTTP structures do not support body transfer using GET, Elasticsearch also offers POST backup.

Regarding the use of a large number of URL parameters, you should keep in mind two problems:

  • URLs are not of unlimited length. There are some differences between browsers, but this is usually a maximum of a few kilobytes. In particular, some older mobile browsers have limitations. It's pretty easy to run into this limit if you put a lot of things into the request, and basically that means the URLs are truncated.
  • Long URIs look ugly and you don’t have to display them in the web interface.
+2
source

Rest is nothing more than a technique / structure / procedure.

This does not apply to a simple servlet call. It always follows standard query conditions.

GET Retrieve any data from the server. You can have any number of parameters with a limit of 256 characters. Parameters should only act as a filter for incoming data, and they should not change the system.

https://www.google.co.in/search?q=google&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

If you see the above URL, you can see many parameters. But they just filter the results. They do not change the system.

POST Send some data in such a way that they change the system, usually adding / removing data.

PUT is something special, say, a POST promotion, which will be used if you want to update existing data.

+1
source

Source: https://habr.com/ru/post/1480846/


All Articles