Skip to content

Commit cac05e4

Browse files
Version Bump:2.1.0: DELETE can now have a request body
1 parent 2272572 commit cac05e4

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33

44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6+
## [2.1.0] - 2016-06-08
7+
### Added
8+
- DELETE can now have a request body
9+
610
## [2.0.0] - 2016-06-03
711
### Changed
812
- Made the Request and Response variables non-redundant. e.g. request.requestBody becomes request.body

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ apply plugin: 'maven'
1717
apply plugin: 'signing'
1818

1919
group = 'com.sendgrid'
20-
version = '2.0.0'
20+
version = '2.1.0'
2121
ext.packaging = 'jar'
2222

2323
allprojects {

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<packaging>jar</packaging>
1212
<name>A simple HTTP client</name>
1313
<description>HTTP REST client, simplified for Java</description>
14-
<version>2.0.0</version>
14+
<version>2.1.0</version>
1515
<url>https://github.com/sendgrid/java-http-client</url>
1616
<licenses>
1717
<license>

src/main/java/com/sendgrid/Client.java

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.sendgrid;
22

33
import org.apache.http.Header;
4+
import org.apache.http.annotation.NotThreadSafe;
45
import org.apache.http.client.ResponseHandler;
56
import org.apache.http.client.methods.CloseableHttpResponse;
7+
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
68
import org.apache.http.client.methods.HttpDelete;
79
import org.apache.http.client.methods.HttpGet;
810
import org.apache.http.client.methods.HttpPatch;
@@ -33,6 +35,21 @@
3335
import java.util.Map;
3436
import java.util.Scanner;
3537

38+
// Hack to get DELETE to accept a request body
39+
@NotThreadSafe
40+
class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase {
41+
public static final String METHOD_NAME = "DELETE";
42+
43+
public String getMethod() {
44+
return METHOD_NAME;
45+
}
46+
47+
public HttpDeleteWithBody(final String uri) {
48+
super();
49+
setURI(URI.create(uri));
50+
}
51+
}
52+
3653
/**
3754
* Class Client allows for quick and easy access any REST or REST-like API.
3855
*/
@@ -286,11 +303,11 @@ public Response delete(Request request) throws URISyntaxException, IOException {
286303
CloseableHttpResponse serverResponse = null;
287304
Response response = new Response();
288305
URI uri = null;
289-
HttpDelete httpDelete = null;
306+
HttpDeleteWithBody httpDelete = null;
290307

291308
try {
292309
uri = buildUri(request.baseUri, request.endpoint, request.queryParams);
293-
httpDelete = new HttpDelete(uri.toString());
310+
httpDelete = new HttpDeleteWithBody(uri.toString());
294311
} catch (URISyntaxException ex) {
295312
throw ex;
296313
}
@@ -301,6 +318,12 @@ public Response delete(Request request) throws URISyntaxException, IOException {
301318
}
302319
}
303320

321+
try {
322+
httpDelete.setEntity(new StringEntity(request.body));
323+
} catch (IOException ex) {
324+
throw ex;
325+
}
326+
304327
try {
305328
serverResponse = httpClient.execute(httpDelete);
306329
response = getResponse(serverResponse);

0 commit comments

Comments
 (0)