Skip to content

Commit c87f863

Browse files
Justintime50claude
andauthored
feat: add a generic API request interface (#374)
# Description Adds a generic API request interface to make arbitrary API requests. # Testing - New unit test added for the generic API request interface - All tests passing --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent aa71613 commit c87f863

File tree

7 files changed

+166
-4
lines changed

7 files changed

+166
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## v8.7.0 (2026-02-25)
4+
5+
- Adds generic `makeApiCall` function
6+
37
## v8.6.0 (2026-02-03)
48

59
- Adds the following functions usable by child and referral customer users:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Add this to your project's POM:
1616
<dependency>
1717
<groupId>com.easypost</groupId>
1818
<artifactId>easypost-api-client</artifactId>
19-
<version>8.6.0</version>
19+
<version>8.7.0</version>
2020
</dependency>
2121
```
2222

@@ -25,7 +25,7 @@ Add this to your project's POM:
2525
Add this to your project's build file:
2626

2727
```groovy
28-
implementation "com.easypost:easypost-api-client:8.6.0"
28+
implementation "com.easypost:easypost-api-client:8.7.0"
2929
```
3030

3131
**NOTE:** [Google Gson](http://code.google.com/p/google-gson/) is required.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.6.0
1+
8.7.0

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>com.easypost</groupId>
77
<artifactId>easypost-api-client</artifactId>
88

9-
<version>8.6.0</version>
9+
<version>8.7.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>com.easypost:easypost-api-client</name>

src/main/java/com/easypost/service/EasyPostClient.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package com.easypost.service;
22

3+
import java.util.Map;
34
import java.util.function.Function;
45

56
import com.easypost.Constants;
7+
import com.easypost.exception.EasyPostException;
68
import com.easypost.exception.General.MissingParameterError;
79
import com.easypost.hooks.RequestHook;
810
import com.easypost.hooks.RequestHookResponses;
911
import com.easypost.hooks.ResponseHook;
1012
import com.easypost.hooks.ResponseHookResponses;
13+
import com.easypost.http.Requestor;
14+
import com.easypost.http.Requestor.RequestMethod;
1115

1216
import lombok.Getter;
1317

@@ -215,4 +219,23 @@ public String getApiVersion() {
215219
public String getApiBase() {
216220
return apiBase;
217221
}
222+
223+
/**
224+
* Make an API call to the EasyPost API.
225+
*
226+
* This public, generic interface is useful for making arbitrary API calls to the EasyPost API that
227+
* are not yet supported by the client library's services. When possible, the service for your use case
228+
* should be used instead as it provides a more convenient and higher-level interface depending on the endpoint.
229+
*
230+
* @param method The HTTP method to use for the request.
231+
* @param endpoint The endpoint to call (e.g., "/addresses").
232+
* @param params The parameters to send with the request.
233+
* @return A Map containing the API response.
234+
* @throws EasyPostException when the request fails.
235+
*/
236+
@SuppressWarnings("unchecked")
237+
public Map<String, Object> makeApiCall(RequestMethod method, String endpoint, Map<String, Object> params)
238+
throws EasyPostException {
239+
return Requestor.request(method, endpoint, params, Map.class, this);
240+
}
218241
}

src/test/cassettes/client/make_api_call.json

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.easypost;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.util.HashMap;
6+
import java.util.List;
7+
import java.util.Map;
8+
9+
import org.junit.jupiter.api.BeforeAll;
10+
import org.junit.jupiter.api.Test;
11+
12+
import com.easypost.exception.EasyPostException;
13+
import com.easypost.http.Requestor.RequestMethod;
14+
15+
public final class EasyPostClientTest {
16+
private static TestUtils.VCR vcr;
17+
18+
/**
19+
* Set up the testing environment for this file.
20+
*
21+
* @throws EasyPostException when the request fails.
22+
*/
23+
@BeforeAll
24+
public static void setup() throws EasyPostException {
25+
vcr = new TestUtils.VCR("client", TestUtils.ApiKey.TEST);
26+
}
27+
28+
/**
29+
* Test making a generic API call.
30+
*
31+
* @throws EasyPostException when the request fails.
32+
*/
33+
@Test
34+
public void testMakeApiCall() throws EasyPostException {
35+
vcr.setUpTest("make_api_call");
36+
37+
Map<String, Object> params = new HashMap<>();
38+
params.put("page_size", 1);
39+
40+
Map<String, Object> response = vcr.client.makeApiCall(RequestMethod.GET, "addresses", params);
41+
42+
List<?> addresses = (List<?>) response.get("addresses");
43+
assertEquals(1, addresses.size());
44+
Map<String, Object> firstAddress = (Map<String, Object>) addresses.get(0);
45+
assertEquals("Address", firstAddress.get("object"));
46+
}
47+
}

0 commit comments

Comments
 (0)