...
Code Block |
---|
http://my.company.com/myapp/orders/1 http://my.company.com/myapp/orders/1.xml http://my.company.com/myapp/orders/1.xhtml http://my.company.com/myapp/orders/1.json |
and the framework handles the serialization and deserialization automaticallyThe REST plugin automatically handles serialization to, and deserialization from, each format.
Features
- Fully implements Ruby -On-on Rails RestREST-style URLs
- Supports XML-free development, without requiring annotations
- Built-in serialization and deserialization support for XML and JSON
- Automatic error handling of errors
- Type-safe configuration of the HTTP response
- Automatic conditional GET support
...
Code Block | ||
---|---|---|
| ||
<!-- ... --> <init-param> <param-name>struts.devMode</param-name> <param-value>true</param-value> </init-param> </filter> |
Next, create Java objects ending in "Controller" in the configured package. The "Controller" suffix is used to distinguish Rest 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:
...
You may wonder why the show()
method returns a HttpHeaders
object and the update()
method returns the expected result code String. Well, the Rest The REST Plugin adds in support for action methods that return HttpHeaders
objects as a way for the action to have more control over the response. In this example, we wanted to ensure the response included the ETag header and a last modified date so that the information will be cached properly by the client. The HttpHeaders
object is a convenient way to control the response in a type-safe way.
...
Setting | Description | Default | Possible Values |
---|---|---|---|
| The alias for the | N/A | Any declared alias for a |
{{ | The default extension to use when none is explicitly specified in the request | | Any extension |
| Whether to disable the scanning of the classpath for controllers or not | | true or false |
...
This plugin can be installed by copying the plugin jar into your application's /WEB-INF/lib
directory. It does depend The REST plugin is dependent on the Codebehind Plugin, so if aren't using a build system that supports transitive dependencies like Maven 2, you will need to add that plugin as well.
...
- http://www.b-simple.de/documents - Short RESTful rails Rails tutorial (PDF in , multiple languages)
- RESTful Web Services - Highly recommend book from O'Reilly
- Go Light with Apache Struts 2 and REST - presentation Presentation by Don Brown at ApacheCon US 2008
...