Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alphaolomi/json-placeholder
JSON Placeholder for PHP, A Free fake API for testing and prototyping.
https://github.com/alphaolomi/json-placeholder
jsonplaceholder php php-library sdk
Last synced: 3 months ago
JSON representation
JSON Placeholder for PHP, A Free fake API for testing and prototyping.
- Host: GitHub
- URL: https://github.com/alphaolomi/json-placeholder
- Owner: alphaolomi
- License: mit
- Created: 2023-03-08T03:16:47.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-29T10:55:05.000Z (9 months ago)
- Last Synced: 2024-05-21T05:14:16.671Z (9 months ago)
- Topics: jsonplaceholder, php, php-library, sdk
- Language: PHP
- Homepage: https://alphaolomi.github.io/json-placeholder/
- Size: 46.9 KB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/funding.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# Json Placeholder for PHP
[![Latest Version on Packagist](https://img.shields.io/packagist/v/alphaolomi/json-placeholder.svg?style=flat-square)](https://packagist.org/packages/alphaolomi/json-placeholder)
[![Tests](https://img.shields.io/github/actions/workflow/status/alphaolomi/json-placeholder/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/alphaolomi/json-placeholder/actions/workflows/run-tests.yml)
[![Total Downloads](https://img.shields.io/packagist/dt/alphaolomi/json-placeholder.svg?style=flat-square)](https://packagist.org/packages/alphaolomi/json-placeholder)A PHP SDK for the [JSON Placeholder API](https://jsonplaceholder.typicode.com/).
## Installation
You can install the package via composer:
```bash
composer require alphaolomi/json-placeholder
```## Usage
```php
$api = new Json\Api();$users = $api->users()->list();
foreach($users as $user) {
echo $user->name;
}
```Shorthand
```php
$users = (new Json\Api())->users()->list();print_r($users);
// array:10 [
// 0 => array:8 [
// "id" => 1
// "name" => "Leanne Graham"
// "username" => "Bret"
// "email" => "[email protected]"
// "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.
```php
$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 PestPHP Testing framework, run the following command to execute the tests.
```bash
composer test
```## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.
## Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## Credits
- [Alpha Olomi](https://github.com/alphaolomi)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.