walker-tx / esv-sdk-php
Requires
- php: ^8.2
- brick/date-time: ^0.7.0
- brick/math: ^0.12.1
- galbar/jsonpath: ^3.0
- guzzlehttp/guzzle: ^7.0
- phpdocumentor/type-resolver: ^1.8
- speakeasy/serializer: ^4.0.3
Requires (Dev)
- laravel/pint: ^1.21.2
- orchestra/testbench: ^9.6
- phpstan/phpstan: ^2.1.0
- phpunit/phpunit: ^10
- roave/security-advisories: dev-latest
This package is auto-updated.
Last update: 2025-05-25 13:31:08 UTC
README
Important
This is not an official SDK developed by Esv.org.
Developer-friendly & type-safe Php SDK specifically catered to leverage walker-tx/esv API.
Summary
ESV.org API: A convenient way to fetch content from ESV.org.
The ESV API provides access to the ESV text, with a customizable presentation in multiple formats.
For more information about the API: ESV API Website
Table of Contents
SDK Installation
The SDK relies on Composer to manage its dependencies.
To install the SDK and add it as a dependency to an existing composer.json
file:
composer require "walker-tx/esv-sdk-php"
SDK Example Usage
Example
declare(strict_types=1); require 'vendor/autoload.php'; use WalkerTx\Esv; use WalkerTx\Esv\Models\Operations; $sdk = Esv\Esv::builder() ->setSecurity( '<YOUR_API_KEY_HERE>' ) ->build(); $request = new Operations\GetPassageHtmlRequest( query: '<value>', ); $response = $sdk->passages->getHtml( request: $request ); if ($response->passageResponse !== null) { // handle response }
Authentication
Per-Client Security Schemes
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
apiKey |
apiKey | API key |
To authenticate with the API the apiKey
parameter must be set when initializing the SDK. For example:
declare(strict_types=1); require 'vendor/autoload.php'; use WalkerTx\Esv; use WalkerTx\Esv\Models\Operations; $sdk = Esv\Esv::builder() ->setSecurity( '<YOUR_API_KEY_HERE>' ) ->build(); $request = new Operations\GetPassageHtmlRequest( query: '<value>', ); $response = $sdk->passages->getHtml( request: $request ); if ($response->passageResponse !== null) { // handle response }
Available Resources and Operations
Pagination
Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the
returned object will be a Generator
instead of an individual response.
Working with generators is as simple as iterating over the responses in a foreach
loop, and you can see an example below:
declare(strict_types=1); require 'vendor/autoload.php'; use WalkerTx\Esv; $sdk = Esv\Esv::builder() ->setSecurity( '<YOUR_API_KEY_HERE>' ) ->build(); $responses = $sdk->passages->search( query: '<value>', pageSize: 20, page: 1 ); foreach ($responses as $response) { if ($response->statusCode === 200) { // handle response } }
Error Handling
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.
By default an API error will raise a Errors\APIException
exception, which has the following properties:
Property | Type | Description |
---|---|---|
$message |
string | The error message |
$statusCode |
int | The HTTP status code |
$rawResponse |
?\Psr\Http\Message\ResponseInterface | The raw HTTP response |
$body |
string | The response content |
When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the getHtml
method throws the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
Errors\Error | 400, 401 | application/json |
Errors\APIException | 4XX, 5XX | */* |
Example
declare(strict_types=1); require 'vendor/autoload.php'; use WalkerTx\Esv; use WalkerTx\Esv\Models\Errors; use WalkerTx\Esv\Models\Operations; $sdk = Esv\Esv::builder() ->setSecurity( '<YOUR_API_KEY_HERE>' ) ->build(); try { $request = new Operations\GetPassageHtmlRequest( query: '<value>', ); $response = $sdk->passages->getHtml( request: $request ); if ($response->passageResponse !== null) { // handle response } } catch (Errors\ErrorThrowable $e) { // handle $e->$container data throw $e; } catch (Errors\APIException $e) { // handle default exception throw $e; }
Server Selection
Override Server URL Per-Client
The default server can be overridden globally using the setServerUrl(string $serverUrl)
builder method when initializing the SDK client instance. For example:
declare(strict_types=1); require 'vendor/autoload.php'; use WalkerTx\Esv; use WalkerTx\Esv\Models\Operations; $sdk = Esv\Esv::builder() ->setServerURL('https://api.esv.org/v3/') ->setSecurity( '<YOUR_API_KEY_HERE>' ) ->build(); $request = new Operations\GetPassageHtmlRequest( query: '<value>', ); $response = $sdk->passages->getHtml( request: $request ); if ($response->passageResponse !== null) { // handle response }
Development
Maturity
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
Contributions
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.