Skip to content
tfredrich edited this page Sep 17, 2012 · 18 revisions

Welcome to the RestExpress Plugins wiki!

Cache Control Plugin

For GET requests, adds a Date: header, if not already present. This enables clients to determine age of a representation for caching purposes.

is in RFC1123 full date format.

Note that HEAD requests are not provided with a Date header via this postprocessor. This is due to the fact that most external caches forward HEAD requests to the origin server as a GET request and cache the result.

For GET requests, adds caching control headers. May be used in conjunction with DateHeaderPostprocessor to add Date header for GET requests.

If the route has a Parameters.Cache.MAX_AGE parameter, whose value is the max-age in seconds then the following are added:

  • Cache-Control: max-age=
  • Expires: now + max-age

If the route has a Flags.Cache.NO_CACHE flag, then the following headers are set on the response:

  • Cache-Control: no-cache
  • Pragma: no-cache

The MAX_AGE parameter takes precidence, in that, if present, the NO_CACHE flag is ignored.

If the response body is non-null, adds an ETag header. ETag is computed from the body object's hash code combined with the hash code of the resulting format.

NOTE: To fully support basic caching capability, also implement a LastModifiedHeaderPostprocessor() that inspects the date on your domain or presentation model and sets the 'Last-Modified' header.

Example Usage:

RestExpress server = new RestExpress();
...
new CacheControlPlugin()
    .register(server);
server.addPostprocessor(new LastModifiedHeaderProcessor());

CORS HeaderPlugin

Adds support for CORS (Cross-origin Resource Sharing) setting the 'Access-Control-Allow-Origin' header on the response for GET requests.

Usage requires passing in the appropriate domain names (comma-separated) that are allowed to perform cross-domain behaviors. To support cross-domain behavior globally (not recommended) send in '*'.

Example Usage:

RestExpress server = new RestExpress();
...
new CorsHeaderPlugin("*")
    .register(server);
or...
server.registerPlugin(new CorsHeaderPlugin("*"));

Routes Metadata Plugin

Adds several routes within your service suite to facilitate auto-discovery of what's available:

Example Usage:

new RoutesMetadataPlugin()
    .register(server)
    .parameter(Parameters.Cache.MAX_AGE, 86400);  // Cache for 1 day (24 hours).

Added Routes:

  • /routes/metadata.{format} - lists details on all routes available.

Sample Payload (XML):

Sample Payload (JSON):

  • /routes/{routeName}/metadata.{format} - lists details on a single, named route.

Sample Payload (XML):

Sample Payload (JSON):

Clone this wiki locally