diff --git a/src/main/java/com/goebl/david/Request.java b/src/main/java/com/goebl/david/Request.java
index 5a31948..2aa84fe 100755
--- a/src/main/java/com/goebl/david/Request.java
+++ b/src/main/java/com/goebl/david/Request.java
@@ -19,7 +19,7 @@
*/
public class Request {
public enum Method {
- GET, POST, PUT, DELETE
+ GET, POST, PUT, DELETE, PATCH
}
private final Webb webb;
diff --git a/src/main/java/com/goebl/david/Webb.java b/src/main/java/com/goebl/david/Webb.java
index 45c2aec..0c91ab4 100755
--- a/src/main/java/com/goebl/david/Webb.java
+++ b/src/main/java/com/goebl/david/Webb.java
@@ -255,6 +255,16 @@ public Request delete(String pathOrUri) {
return new Request(this, Request.Method.DELETE, buildPath(pathOrUri));
}
+ /**
+ * Creates a PATCH HTTP request with the specified absolute or relative URI.
+ * @param pathOrUri the URI (will be concatenated with global URI or default URI without further checking)
+ * If it starts already with http:// or https:// this URI is taken and all base URIs are ignored.
+ * @return the created Request object (in fact it's more a builder than a real request object)
+ */
+ public Request patch(String pathOrUri) {
+ return new Request(this, Request.Method.PATCH, buildPath(pathOrUri));
+ }
+
private String buildPath(String pathOrUri) {
if (pathOrUri == null) {
throw new IllegalArgumentException("pathOrUri must not be null");
diff --git a/src/test/api-test-server/routes/simple.js b/src/test/api-test-server/routes/simple.js
index 52542a9..872d950 100755
--- a/src/test/api-test-server/routes/simple.js
+++ b/src/test/api-test-server/routes/simple.js
@@ -28,6 +28,10 @@ module.exports = function registerRoutes(app) {
res.send(204);
});
+ app.patch('/simple.json', function (req, res) {
+ res.json(req.body);
+ });
+
app.get('/no-content', function (req, res) {
res.send(204);
});
diff --git a/src/test/java/com/goebl/david/TestWebb.java b/src/test/java/com/goebl/david/TestWebb.java
index 3e8d1d7..3420850 100755
--- a/src/test/java/com/goebl/david/TestWebb.java
+++ b/src/test/java/com/goebl/david/TestWebb.java
@@ -138,6 +138,24 @@ public void testSimpleDelete() throws Exception {
assertEquals("No Content", response.getResponseMessage());
}
+ public void testSimplePatchJson() throws Exception {
+ JSONObject payload = new JSONObject();
+ payload.put("p1", SIMPLE_ASCII);
+ payload.put("p2", COMPLEX_UTF8);
+
+ Response response = webb
+ .patch("/simple.json")
+ .body(payload)
+ .asJsonObject();
+
+ assertEquals(200, response.getStatusCode());
+ assertTrue(response.getContentType().startsWith(Webb.APP_JSON));
+ JSONObject result = response.getBody();
+ assertNotNull(result);
+ assertEquals(SIMPLE_ASCII, result.getString("p1"));
+ assertEquals(COMPLEX_UTF8, result.getString("p2"));
+ }
+
public void testNoContent() throws Exception {
Response responseAsVoid = webb