Hosted by Three Crickets

Prudence
Scalable REST Platform
For the JVM

Prudence logo: bullfinch in flight

String Interpolation

Template variables, delimited by curly brackets, can be used to interpolate strings for three use cases:
Prudence supports many built-in interpolation variables, extracted from the conversation attributes and summarized below. See also the related Restlet API documentation.
Note that for cache key templates, it's possible to create your own interpolation variables using plugins.

Request URIs

These variables are composed of a prefix and a suffix. The prefix specifies which URI you are referring to, while the suffix specifies the part of that URI. For example, the prefix "{r-}" can be combined with the suffix "{-i}" for "{ri}", to specify the complete request URI.

Prefixes

Suffixes

Base URIs

Every URI also has a "base" version of it: in the case of wildcard URI templates, it is the URI before the wildcard begins. Otherwise it is usually the application's root URI on the virtual host. It is used in the "{-r}" and "{-e}" suffixes above.
To refer to the base URI directly, use the special "{-b-}" infix, to which you would still need to add one of the above suffixes. For example, "{rbi}" refers to the complete base URI of the actual URI.

Relative URIs

For cache key templates only, you can also use the "{cb}" variable. It is equivalent to calling the conversation.base API.

Interpolating the Wildcard

This is a common use case for redirection, so even though it's included in the documentation above, it's worth emphasizing. According to the rules, the "*" would be the "{rw}" variable. For example:
app.routes = {
	...
	'/assets/*': '/files/media/{rw}'
}
The above would capture a URI such as "/assets/images/logo.png" to "/files/media/images/logo.png".
The wildcard can also be accessed via API.

Request Attributes

Client Attributes

Payload Attributes

All these refer to the payload ("entity") sent by the client.

Negotiated Attributes

These are the result of content negotiation, and are used specifically for cache key templates.

Implementation Attributes

These are used specifically for cache key templates.

Response Attributes

These attributes are not normally used in Prudence—they are not used in routing nor in cache key templates—but are mentioned here for completion. They are all in uppercase to differentiate them from the request variables:
Additionally, all the entity attributes can be used in uppercase to correspond to the response entity. For example, "{ES}" for the response entity size, "{EMT}" for the response media type, etc.

conversation.locals

As we've seen in the app.routes guide, URI templates delimited by curly brackets can be used to parse incoming request URIs and extract the values into conversation.locals. For example, a "/person/{id}/" URI template will match the "/person/linus/" URI and extract "linus" into the "id" conversation.local.
But you can also do the opposite: interpolate the values that were extracted from the matched URI template. An example of redirection that both extracts and interpolates:
app.routes = {
	...
	"/person/{id}/": ">http://newsite.org/profile/?id={id}"
}

The Prudence Manual is provided for you under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. The complete manual is available for download as a PDF.

Download manual as PDF Creative Commons License