Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Contents
minLevel2
outlinetrue

Features

  • Fully implements Ruby on Rails REST-style URLs
  • Supports XML-free development, without requiring annotations
  • Built-in serialization and deserialization support for XML and JSON
  • Automatic error handling
  • Type-safe configuration of the HTTP response
  • Automatic conditional GET support

Overview

The REST Plugin

Excerpt

provides high level support for the implementation of RESTful resource based web applications

The REST Plugin
Excerpt

simplifies REST-style resources to be consumed by both human and machine clients

. The goals are to 100% follow Ruby on Rails-style REST URL conventions and enable XML-free resource development. The REST plugin can cooperate with the Convention Plugin to support automatic configuration of both a zero configuration approach to declaring your actions and results, but you can always use the REST plugin with XML style configuration if you like.

The main functionality of the REST plugin lies in the interpretation of incoming request URL's according the RESTful rules. In the Struts 2 framework, this 'mapping' of request URL's to Actions is handled by in implementation of the ActionMapper interface. Out of the box, Struts 2 uses the DefaultActionMapper to map URL's to Actions via the logic you are probably already familiar with. The REST plugin provides an alternative implementation, RestActionMapper, that provides the RESTful logic. The following section, which comes from the Javadoc for the class, details this logic.

RestActionMapper

Wiki Markup
{snippet:url=rest-plugin/src/main/java/org/apache/struts2/rest/RestActionMapper.java|id=description|javadoc=true}

...

The REST plugin automatically handles serialization to, and deserialization from, each format.

Features

...

Usage

Create Java objects ending in "Controller" in the configured package. The "Controller" suffix is used to distinguish REST action resources from regular Struts 2 actions, although it is completely optional and they are functionally the same. Now, add in methods to handle the various requests. For example, the following resource action will support /orders/34 GET and PUT requests:

...