alphaolomi / json-placeholder
PHP SDK for JSON Placeholder API, A Free fake API for testing and prototyping.
v0.2.0
2023-03-26 22:18 UTC
Requires
- php: ^8.0
- sammyjo20/saloon: ^2.2
Requires (Dev)
- laravel/pint: ^1.0
- pestphp/pest: ^1.22
This package is auto-updated.
Last update: 2024-04-29 10:55:09 UTC
README
A PHP SDK for the JSON Placeholder API.
Installation
Use Composer to install this SDK
composer require alphaolomi/json-placeholder
Usage
$api = new Json\Api(); $users = $api->users()->list(); foreach($users as $user) { echo $user->name; }
Shorthand
$users = (new Json\Api())->users()->list(); print_r($users); // array:10 [ // 0 => array:8 [ // "id" => 1 // "name" => "Leanne Graham" // "username" => "Bret" // "email" => "Sincere@april.biz" // "address" => array:5 [▶] // "phone" => "1-770-736-8031 x56442" // "website" => "hildegard.org" // "company" => array:3 [▶] // ] // 1 => array:8 [▶] // ]
Paginated Results
You may prefer to retrieve all the results from the paginated requests by using the paginator
method on the SDK.
$api = new Json\Api(); $results = $api->users()->paginate(); foreach($results as $result) { // Handle result echo $result->name; }
Available Resources
- Users
- List all users
- Get a single user
- Create a user
- Update a user
- Delete a user
- Paginate users
Testing
Using Pest Testing Framework, run the following command to run the tests.
composer test
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.