Skip to content

Commit 6338fdb

Browse files
Proxy improvements (#195)
* Handle non-JSON payloads and other response types in the Proxy The `proxy` module now supports non-JSON payloads. Since the downstream services that the Proxy can call do not necessarily respond with JSON content, the new logic will inspect the `Content-Type` header in the response to determine whether the payload should be parsed as JSON or returned back to the caller as a byte stream (especially useful for downloading files). ```java ProxyResponse response = client.proxy().get(url, request, requestOptions); // The SDK returns a stream for binary responses if (response.isStream()) { try (InputStream stream = response.stream(); FileOutputStream fos = new FileOutputStream(outputPath)) { byte[] buffer = new byte[8192]; int bytesRead; while ((bytesRead = stream.read(buffer)) != -1) { fos.write(buffer, 0, bytesRead); } } System.out.println("File downloaded to: " + outputPath); } ``` * Improve ergonomics for query parameters When passing query parameters to the downstream service, users had to previously encode them manually inside a `url` string. Now, every method in the Proxy clients accepts an `HttpUrl` instance, which allows users to build URLs with query parameters in a more ergonomic way: ```java HttpUrl url = HttpUrl.parse(GDRIVE_API_BASE) .newBuilder() .addPathSegment(fileId) .addQueryParameter("fields", "name,mimeType,size") .build(); ProxyGetRequest request = ProxyGetRequest.builder() .externalUserId(externalUserId) .accountId(accountId) .build(); ``` --------- Co-authored-by: Jay Vercellone <jay@pipedream.com>
1 parent 06c4e03 commit 6338fdb

File tree

10 files changed

+904
-80
lines changed

10 files changed

+904
-80
lines changed

.fernignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ src/main/java/com/pipedream/api/PipedreamClient.java
2020
src/main/java/com/pipedream/api/PipedreamClientBuilder.java
2121

2222
# Custom Proxy files
23+
src/main/java/com/pipedream/api/resources/proxy/AsyncProxyClient.java
24+
src/main/java/com/pipedream/api/resources/proxy/AsyncRawProxyClient.java
25+
src/main/java/com/pipedream/api/resources/proxy/ProxyClient.java
26+
src/main/java/com/pipedream/api/resources/proxy/RawProxyClient.java
27+
src/main/java/com/pipedream/api/resources/proxy/requests/ProxyDeleteRequest.java
28+
src/main/java/com/pipedream/api/resources/proxy/requests/ProxyGetRequest.java
29+
src/main/java/com/pipedream/api/resources/proxy/requests/ProxyPatchRequest.java
30+
src/main/java/com/pipedream/api/resources/proxy/requests/ProxyPostRequest.java
31+
src/main/java/com/pipedream/api/resources/proxy/requests/ProxyPutRequest.java
32+
src/main/java/com/pipedream/api/resources/proxy/types/ProxyResponse.java
2333

2434
# Custom Workflow files
2535
src/main/java/com/pipedream/api/resources/workflows/AsyncWorkflowsClient.java

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55

66
The Pipedream Java library provides convenient access to the Pipedream APIs from Java.
77

8+
## Table of Contents
9+
10+
- [Installation](#installation)
11+
- [Usage](#usage)
12+
- [Environments](#environments)
13+
- [Base Url](#base-url)
14+
- [Exception Handling](#exception-handling)
15+
- [Advanced](#advanced)
16+
- [Custom Client](#custom-client)
17+
- [Retries](#retries)
18+
- [Timeouts](#timeouts)
19+
- [Custom Headers](#custom-headers)
20+
- [Contributing](#contributing)
21+
- [Reference](#reference)
22+
823
## Installation
924

1025
### Gradle
@@ -25,7 +40,7 @@ Add the dependency in your `pom.xml` file:
2540
<dependency>
2641
<groupId>com.pipedream</groupId>
2742
<artifactId>pipedream</artifactId>
28-
<version>1.1.0</version>
43+
<version>1.1.1</version>
2944
</dependency>
3045
```
3146

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ java {
4949

5050
group = 'com.pipedream'
5151

52-
version = '1.1.0'
52+
version = '1.1.1'
5353

5454
jar {
5555
dependsOn(":generatePomFileForMavenPublication")
@@ -80,7 +80,7 @@ publishing {
8080
maven(MavenPublication) {
8181
groupId = 'com.pipedream'
8282
artifactId = 'pipedream'
83-
version = '1.1.0'
83+
version = '1.1.1'
8484
from components.java
8585
pom {
8686
name = 'pipedream'

src/main/java/com/pipedream/api/core/ClientOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ private ClientOptions(
3535
this.headers.putAll(headers);
3636
this.headers.putAll(new HashMap<String, String>() {
3737
{
38-
put("User-Agent", "com.pipedream:pipedream/1.1.0");
38+
put("User-Agent", "com.pipedream:pipedream/1.1.1");
3939
put("X-Fern-Language", "JAVA");
4040
put("X-Fern-SDK-Name", "com.pipedream.fern:api-sdk");
41-
put("X-Fern-SDK-Version", "1.1.0");
41+
put("X-Fern-SDK-Version", "1.1.1");
4242
}
4343
});
4444
this.headerSuppliers = headerSuppliers;

src/main/java/com/pipedream/api/resources/proxy/AsyncProxyClient.java

Lines changed: 86 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import com.pipedream.api.resources.proxy.requests.ProxyPatchRequest;
1111
import com.pipedream.api.resources.proxy.requests.ProxyPostRequest;
1212
import com.pipedream.api.resources.proxy.requests.ProxyPutRequest;
13+
import com.pipedream.api.resources.proxy.types.ProxyResponse;
1314
import java.util.Base64;
1415
import java.util.concurrent.CompletableFuture;
16+
import okhttp3.HttpUrl;
1517

1618
public class AsyncProxyClient {
1719
protected final ClientOptions clientOptions;
@@ -37,80 +39,154 @@ public AsyncRawProxyClient withRawResponse() {
3739
/**
3840
* Forward an authenticated GET request to an external API using an external user's account credentials
3941
*/
40-
public CompletableFuture<Object> get(String url, ProxyGetRequest request) {
42+
public CompletableFuture<ProxyResponse> get(String url, ProxyGetRequest request) {
4143
final String url64 = encodeUrl(url);
4244
return this.rawClient.get(url64, request).thenApply(response -> response.body());
4345
}
4446

4547
/**
4648
* Forward an authenticated GET request to an external API using an external user's account credentials
4749
*/
48-
public CompletableFuture<Object> get(String url, ProxyGetRequest request, RequestOptions requestOptions) {
50+
public CompletableFuture<ProxyResponse> get(HttpUrl url, ProxyGetRequest request) {
51+
return get(url.toString(), request);
52+
}
53+
54+
/**
55+
* Forward an authenticated GET request to an external API using an external user's account credentials
56+
*/
57+
public CompletableFuture<ProxyResponse> get(String url, ProxyGetRequest request, RequestOptions requestOptions) {
4958
final String url64 = encodeUrl(url);
5059
return this.rawClient.get(url64, request, requestOptions).thenApply(response -> response.body());
5160
}
5261

62+
/**
63+
* Forward an authenticated GET request to an external API using an external user's account credentials
64+
*/
65+
public CompletableFuture<ProxyResponse> get(HttpUrl url, ProxyGetRequest request, RequestOptions requestOptions) {
66+
return get(url.toString(), request, requestOptions);
67+
}
68+
5369
/**
5470
* Forward an authenticated POST request to an external API using an external user's account credentials
5571
*/
56-
public CompletableFuture<Object> post(String url, ProxyPostRequest request) {
72+
public CompletableFuture<ProxyResponse> post(String url, ProxyPostRequest request) {
5773
final String url64 = encodeUrl(url);
5874
return this.rawClient.post(url64, request).thenApply(response -> response.body());
5975
}
6076

6177
/**
6278
* Forward an authenticated POST request to an external API using an external user's account credentials
6379
*/
64-
public CompletableFuture<Object> post(String url, ProxyPostRequest request, RequestOptions requestOptions) {
80+
public CompletableFuture<ProxyResponse> post(HttpUrl url, ProxyPostRequest request) {
81+
return post(url.toString(), request);
82+
}
83+
84+
/**
85+
* Forward an authenticated POST request to an external API using an external user's account credentials
86+
*/
87+
public CompletableFuture<ProxyResponse> post(String url, ProxyPostRequest request, RequestOptions requestOptions) {
6588
final String url64 = encodeUrl(url);
6689
return this.rawClient.post(url64, request, requestOptions).thenApply(response -> response.body());
6790
}
6891

92+
/**
93+
* Forward an authenticated POST request to an external API using an external user's account credentials
94+
*/
95+
public CompletableFuture<ProxyResponse> post(HttpUrl url, ProxyPostRequest request, RequestOptions requestOptions) {
96+
return post(url.toString(), request, requestOptions);
97+
}
98+
6999
/**
70100
* Forward an authenticated PUT request to an external API using an external user's account credentials
71101
*/
72-
public CompletableFuture<Object> put(String url, ProxyPutRequest request) {
102+
public CompletableFuture<ProxyResponse> put(String url, ProxyPutRequest request) {
73103
final String url64 = encodeUrl(url);
74104
return this.rawClient.put(url64, request).thenApply(response -> response.body());
75105
}
76106

77107
/**
78108
* Forward an authenticated PUT request to an external API using an external user's account credentials
79109
*/
80-
public CompletableFuture<Object> put(String url, ProxyPutRequest request, RequestOptions requestOptions) {
110+
public CompletableFuture<ProxyResponse> put(HttpUrl url, ProxyPutRequest request) {
111+
return put(url.toString(), request);
112+
}
113+
114+
/**
115+
* Forward an authenticated PUT request to an external API using an external user's account credentials
116+
*/
117+
public CompletableFuture<ProxyResponse> put(String url, ProxyPutRequest request, RequestOptions requestOptions) {
81118
final String url64 = encodeUrl(url);
82119
return this.rawClient.put(url64, request, requestOptions).thenApply(response -> response.body());
83120
}
84121

122+
/**
123+
* Forward an authenticated PUT request to an external API using an external user's account credentials
124+
*/
125+
public CompletableFuture<ProxyResponse> put(HttpUrl url, ProxyPutRequest request, RequestOptions requestOptions) {
126+
return put(url.toString(), request, requestOptions);
127+
}
128+
85129
/**
86130
* Forward an authenticated DELETE request to an external API using an external user's account credentials
87131
*/
88-
public CompletableFuture<Object> delete(String url, ProxyDeleteRequest request) {
132+
public CompletableFuture<ProxyResponse> delete(String url, ProxyDeleteRequest request) {
89133
final String url64 = encodeUrl(url);
90134
return this.rawClient.delete(url64, request).thenApply(response -> response.body());
91135
}
92136

93137
/**
94138
* Forward an authenticated DELETE request to an external API using an external user's account credentials
95139
*/
96-
public CompletableFuture<Object> delete(String url, ProxyDeleteRequest request, RequestOptions requestOptions) {
140+
public CompletableFuture<ProxyResponse> delete(HttpUrl url, ProxyDeleteRequest request) {
141+
return delete(url.toString(), request);
142+
}
143+
144+
/**
145+
* Forward an authenticated DELETE request to an external API using an external user's account credentials
146+
*/
147+
public CompletableFuture<ProxyResponse> delete(
148+
String url, ProxyDeleteRequest request, RequestOptions requestOptions) {
97149
final String url64 = encodeUrl(url);
98150
return this.rawClient.delete(url64, request, requestOptions).thenApply(response -> response.body());
99151
}
100152

153+
/**
154+
* Forward an authenticated DELETE request to an external API using an external user's account credentials
155+
*/
156+
public CompletableFuture<ProxyResponse> delete(
157+
HttpUrl url, ProxyDeleteRequest request, RequestOptions requestOptions) {
158+
return delete(url.toString(), request, requestOptions);
159+
}
160+
101161
/**
102162
* Forward an authenticated PATCH request to an external API using an external user's account credentials
103163
*/
104-
public CompletableFuture<Object> patch(String url, ProxyPatchRequest request) {
164+
public CompletableFuture<ProxyResponse> patch(String url, ProxyPatchRequest request) {
105165
final String url64 = encodeUrl(url);
106166
return this.rawClient.patch(url64, request).thenApply(response -> response.body());
107167
}
108168

109169
/**
110170
* Forward an authenticated PATCH request to an external API using an external user's account credentials
111171
*/
112-
public CompletableFuture<Object> patch(String url, ProxyPatchRequest request, RequestOptions requestOptions) {
172+
public CompletableFuture<ProxyResponse> patch(HttpUrl url, ProxyPatchRequest request) {
173+
return patch(url.toString(), request);
174+
}
175+
176+
/**
177+
* Forward an authenticated PATCH request to an external API using an external user's account credentials
178+
*/
179+
public CompletableFuture<ProxyResponse> patch(
180+
String url, ProxyPatchRequest request, RequestOptions requestOptions) {
113181
final String url64 = encodeUrl(url);
114182
return this.rawClient.patch(url64, request, requestOptions).thenApply(response -> response.body());
115183
}
184+
185+
/**
186+
* Forward an authenticated PATCH request to an external API using an external user's account credentials
187+
*/
188+
public CompletableFuture<ProxyResponse> patch(
189+
HttpUrl url, ProxyPatchRequest request, RequestOptions requestOptions) {
190+
return patch(url.toString(), request, requestOptions);
191+
}
116192
}

0 commit comments

Comments
 (0)