Image alternative text

Name: Bouncer

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 retrieve the complex query parameters.

x
10
 
1
POST /showmethekpis/bouncer HTTP/1.1
2
Host: example.org
3
Content-Type: application/sql
4
Content-Length: 64
5
6
SELECT all,the,fields,we,need 
7
FROM tblWhyWouldYou ww JOIN tblBecauseICan bc ON ww.id = bc.whyid 
8
WHERE CrazyFool = 'me' 
9
ORDER BY Sanity
10
11
=>
12
13
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/retrieving 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