A resource designed to accept a request body containing complex query parameters and redirect to a new location to enable the results of complex and expensive queries to be cached.
Problem
There are practical limitations to the length of a URL on the Web. In order to send complex queries it is sometimes necessary to use a POST method and use the request body to describe the query parameters. However, a POST method cannot return a cached response. If the complex queries take a non-trivial amount of time to execute then it may be desirable to cache those results either on the client side or the server side.
Solution
In order to allow complex queries and still allow results to be cached, a Bouncer
resource can be used to accept the POST request with the complex query parameters and redirect to a query resource with a fingerprint value in the URL that can be used to retreive the complex query details.
POST /showmethekpis/bouncer HTTP/1.1
Host: example.org
Content-Type: application/sql
Content-Length: 64
SELECT all,the,fields,we,need
FROM tblWhyWouldYou ww JOIN tblBecauseICan bc ON ww.id = bc.whyid
WHERE CrazyFool = 'me'
ORDER BY Sanity
=>
303 See Other
Location: http://example.org/showmethekpis/query/34342323
Discussion
The bouncer resource is an alternative approach to trying to encode query parameters into URL friendly tokens. The cost is an additional redirect round-trip and the complexity of the server calculating fingerprints and storing query parameters.
The bouncer resource must calculate a fingerprint of the incoming query parameters and store the parameters if they are not previously stored. It is important that two distinct requests that have the same set of query parameter values should generate the same fingerprint in order to take advantage of cached results. This means the bouncer resource may perform some normalization on the query parameters before calculating the fingerprint.
The redirect URL that contains the fingerprint should not be bookmarked by the client as the bouncer resource may choose to expire the stored parameters at anytime.
Related Patterns
[Alias]