arpit joshi
arpit joshi

Reputation: 2144

Params for a GET request for a REST Service Java

I am creating a REST service in Java ,and have a doubt with regards to params for the GET method . I have to pass the below params in a GET request

Function

"GET" File status :

Params:

Time Range:(String)

FlowId:(String)

ID_A= or ID_B= or Both (String)

IS_ADD_A= or IS_ADD_B= or both (String)

Regex=(String)

Cookie=XXXXX

So as there are 6 params,so passing it as a query string would not be an efficient way and can't but the same in body(as it is against the HTTP GET specification) Making this as a POST call would be against the REST principle as I want to get data from the server , What would be an efficient way of solving this ,would passing the params as query string is out of question,passing it in body which is against the HTTP spec ,making this as headers which may also be not good ,making this as POST request which will voilate the fielding's REST principle .

Upvotes: 1

Views: 210

Answers (2)

puczo
puczo

Reputation: 727

If your parameters values aren't very long, using query string is your best option here. 6 params is not a lot, as long you don't exceed the IE limit of characters in the path - 2,048 (http://www.boutell.com/newfaq/misc/urllength.html). For example Google search engine uses many more params then 6. If there is a possibility that the URL path will exceed the limit above, you should use POST instead.

Upvotes: 1

Henri Benoit
Henri Benoit

Reputation: 725

Passing data in the body of an HTTP GET call is not only against the spec but causes problems with various server-side technologies which assume you don't need access to the body in a GET call. (Some client side frameworks also have some issues with GET and a query in the body) If you have queried with long parameters I'd go with POST. It's then using POST for getting data but you'd not be the only one having to go this way to support potentially large queries.

Upvotes: 1

Related Questions