appbaseio / reactivesearch

Search UI components for React and Vue
https://opensource.appbase.io/reactivesearch
Apache License 2.0
4.9k stars 466 forks source link

Use GET requests for searching over POST requests #1230

Closed siddharthlatest closed 4 years ago

siddharthlatest commented 4 years ago

Affected Projects

All

Library Version:

3.0.3

Describe the bug

The _msearch requests made by ReactiveSearch make a POST API call currently. A POST request isn't considered idempotent [1] by HTTP client implementations. (An idempotent request is one that should return the same result irrespective of the number of times it is called.) This is for good reasons as a POST request is typically involved in submission of form data, creation of new resource. A GET request on the other hand is considered idempotent by HTTP client implementations.

The resulting issue due to ReactiveSearch's use of POST when connecting to reverse proxies such as https://github.com/appbaseio/arc is that they don't retry HTTP requests when the ElasticSearch server closes a connection. If a GET request were being made instead by ReactiveSearch (which is possible), Go's HTTP client 2 (and presumably any other HTTP client implementation over any language) would retry such cases.

Recommendation

For searching, ReactiveSearch (and all variants) should switch to using GET requests instead of POST requests.

References: [1]: https://tools.ietf.org/html/rfc7231#section-4.2.1 A Tl;dr version of this is available over at https://stackoverflow.com/questions/45016234/what-is-idempotency-in-http-methods.

bmi2013 commented 4 years ago

The HTTP method that reactivesearch uses, should be an parameter to ReactiveBase so that client can change that based on proxy implementation. AWS cloudfront, e.g., does not allow body in HTTP GET requests. In that case all search requests should be delivered via POST method.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

naddeoa commented 3 years ago

Not sure where this went but it does look like this is possible with the transformRequest api on the base component. No idea if this is the recommended approach. Can't find any documentation.


function SomeComponent(){

    const transformer = (request) => {
        request.method = 'GET'
    }

    return (
        <ReactiveBase transformRequest={transformer} .... >...</ReactiveBase>
    )
}