1

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 .

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

yes I agree that putting body will be against the HTTP spec,and having a POST for getting the data will be against the REST,will it be valid and advisable to use the params as headers ?
You could argue that providing an endpoint for search e.g. myentity/search and sending query criteria per POST wouldn't really be against the REST principles. A query could be a valid entity and POST doesn't need to create something but can.
I wouldn't use headers to transmit query criteria. Headers are for metadata and putting in there contents doesn't feel right.
1

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.

2 Comments

well the 6 params though are not a lot,but their length will be long ,and moreover the URL could suffer,POST will make the remote client confused as he wants to get data but finds that he is using a POST
In that case you should use POST method. It is considered bad practice to transmit actual data as a header field (http://www.soapui.org/testing-dojo/best-practices/understanding-rest-headers-and-parameters.html). You can document your API to avoid confusion.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.