Skip to content

Commit dec39fe

Browse files
Justintime50claude
andauthored
feat: add a generic API request interface (#380)
# Description Adds a generic API request interface to make arbitrary API requests. # Testing - New unit test added for the generic `makeApiCall` method - All tests passing # Pull Request Type Please select the option(s) that are relevant to this PR. - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Improvement (fixing a typo, updating readme, renaming a variable name, etc) --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 5f8184d commit dec39fe

File tree

6 files changed

+142
-2
lines changed

6 files changed

+142
-2
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-20)
48

59
- Adds the following functions:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "easypost/easypost-php",
33
"description": "EasyPost Shipping API Client Library for PHP",
4-
"version": "8.6.0",
4+
"version": "8.7.0",
55
"keywords": [
66
"shipping",
77
"api",

lib/EasyPost/Constant/Constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ abstract class Constants
1111
const BETA_API_VERSION = 'beta';
1212

1313
// Library constants
14-
const LIBRARY_VERSION = '8.6.0';
14+
const LIBRARY_VERSION = '8.7.0';
1515
const SUPPORT_EMAIL = 'support@easypost.com';
1616

1717
// Validation

lib/EasyPost/EasyPostClient.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
use EasyPost\Exception\General\EasyPostException;
77
use EasyPost\Hook\RequestHook;
88
use EasyPost\Hook\ResponseHook;
9+
use EasyPost\Http\Requestor;
910
use EasyPost\Service\AddressService;
11+
use EasyPost\Util\InternalUtil;
1012
use EasyPost\Service\ApiKeyService;
1113
use EasyPost\Service\BaseService;
1214
use EasyPost\Service\BatchService;
@@ -260,4 +262,23 @@ public function unsubscribeFromResponseHook(callable $function): void
260262
{
261263
$this->responseEvent->removeHandler($function);
262264
}
265+
266+
/**
267+
* Make an API call to the EasyPost API.
268+
*
269+
* This public, generic interface is useful for making arbitrary API calls to the EasyPost API that
270+
* are not yet supported by the client library's services. When possible, the service for your use case
271+
* should be used instead as it provides a more convenient and higher-level interface depending on the endpoint.
272+
*
273+
* @param string $method
274+
* @param string $endpoint
275+
* @param mixed $params
276+
* @return mixed
277+
*/
278+
public function makeApiCall(string $method, string $endpoint, mixed $params = null): mixed
279+
{
280+
$response = Requestor::request($this, $method, $endpoint, $params);
281+
282+
return InternalUtil::convertToEasyPostObject($this, $response);
283+
}
263284
}

test/EasyPost/EasyPostClientTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@
88

99
class EasyPostClientTest extends TestCase
1010
{
11+
/**
12+
* Setup the testing environment for this file.
13+
*/
14+
public static function setUpBeforeClass(): void
15+
{
16+
TestUtil::setupVcrTests();
17+
}
18+
19+
/**
20+
* Cleanup the testing environment once finished.
21+
*/
22+
public static function tearDownAfterClass(): void
23+
{
24+
TestUtil::teardownVcrTests();
25+
}
26+
1127
/**
1228
* Test setting and getting the API key for different EasyPostClients.
1329
*/
@@ -66,4 +82,19 @@ public function testInvalidServiceProperty(): void
6682
);
6783
}
6884
}
85+
86+
/**
87+
* Test making an API call using the generic makeApiCall method.
88+
*/
89+
public function testMakeApiCall(): void
90+
{
91+
TestUtil::setupCassette('client/makeApiCall.yml');
92+
93+
$client = new EasyPostClient((string)getenv('EASYPOST_TEST_API_KEY'));
94+
95+
$response = $client->makeApiCall('get', '/addresses', ['page_size' => 1]);
96+
97+
$this->assertCount(1, $response['addresses']);
98+
$this->assertEquals('Address', $response['addresses'][0]['object']);
99+
}
69100
}

test/cassettes/client/makeApiCall.yml

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)