This example demonstrates how to implement generic support for HTTP PATCH Method (RFC-5789) via JAX-RS reader interceptor. The example has been created based on this Gerard Davison's blog entry. The patch format supported by this example is JSON Patch (RFC-6902).
The mapping of the URI path space is presented in the following table:
URI path | Resource class | HTTP methods |
---|---|---|
/patchable-state | PatchableResource | GET, PATCH |
As you can see in the table, there is only a single resource deployed in this application, that supports GET
and PATCH
methods. The resource represents a patchable state, which consists of 3 properties:
title
text property,message
text property, andlist
property that represents a list/array of text strings.This state can be patch via HTTP GET method by sending the desired patch/diff in the JSON Patch format as defined in RFC-6902, for example:
[ { "op" : "replace", "path" : "/message", "value" : "patchedMessage" }, { "op" : "add", "path" : "/list/-", "value" : "one" } ]
This patch will instruct the resource to replace it's message
property content with a new
"patchedMessage"
text and also to append a new "one"
string value to the list
of valued contained in the list
property.
(See HttpPatchTest
for more details.)
Run the example as follows:
mvn clean compile exec:java
This deploys the example using Grizzly container.
A WADL description may be accessed at the URL:
http://localhost:8080/http-patch/application.wadl
The resource is available at
http://localhost:8080/http-patch/patchable-state