REST Resource Asset: Best way to send data in Request body


#1

Matrix Version: 5.2

So I am looking to construct queries to send to a server to retreive some data. Here is an example of a query that I am looking to use.

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html

I was thinking of using a REST Resource, but it seems like that Matrix doesn’t allow to use “Request Body” with the GET verb.

Is jQuery AJAX my only option? I am looking to avoid it if possible due to cross domain issues. I know JSONP can help, but this will be the last option.

Any help is really appreciated. Thanks


Search engine options
(Bart Banda) #2

GET requests usually do not have a message body. http://stackoverflow.com/questions/5216567/is-this-statement-correct-http-get-method-always-has-no-message-body

It’s a very uncommon thing to use it seems (first time I’ve come across it).

Does elastic search support passing the data as standard URL GET parameters instead? Or using POST?


#3

Hi Bart, thanks again for your reply. ElasticSearch does support passing data using standard URL GET parameters, but its a very limited subset of what you can send in GET message body.

For example constructing queries like this and this using standard URL GET parameters would be a pain in the back. That is why they recommend sending queries in message body. Their reasoning/advantage maybe is that it allows easily sending XML or JSON request bodies containing complex nested queries, it doesn’t have a length restriction and it’s easier to encode (UTF-8).

Also, upon further investigation, I came across this old document, which states that Elastic does support POST request with message body, if sending a GET request with message body is not feasible. This is for an older version of Elastic, not sure if the latest version (5.1) that I am using also support this. I gotta do some testing …

Cheers …


(Bart Banda) #4

Thanks for the clarification Paul. Would be interested to know if the POST method is an option, would be surprised if it’s not.