Php json api client

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

A PHP library for working with JSON:API APIs.

License

silverorange/json-api-client

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Читайте также:  Opening pdf file in javascript

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

A PHP library for working with JSON API servers.

The following features are supported:

  • loading resource collections
  • loading individual resources by identifier
  • creating resources
  • saving resources
  • to one relationships
  • to many relationships

The ResourceStore is responsible for performing HTTP requests and caching resources. The following APIs are provided:

  • peek() — look for a cached resource without hitting the backend server
  • query() — look for a resource while always hitting the backend server
  • find() — look for a resource using cache if available, hit the backend if the cached resource is not available
  • create() — make a new resoure
  • save() — save a resource
  • delete() — delete a resource

The Guzzle HTTP library is used to make requests.

Make sure the silverorange composer repository is added to the composer.json for the project and then run:

composer require silverorange/json-api-client

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

👷‍♀️ A PHP Library to handle the request or response body from a JSON API server.

License

Art4/json-api-client

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

JsonApiClient 👷‍♀️ is a PHP Library to validate and handle the response body from a JSON API Server.

  • ✔️ Be 100% JSON API spec conform
  • ✔️ Be open for new spec versions
  • ✔️ Handle/validate a server response body
  • ✔️ Handle/validate a client request body
  • ✔️ Offer an easy way to retrieve the data
  • ✔️ Allow extendability and injection of classes/models
$ composer require art4/json-api-client

Version 1.0 is finally released. 🎉

After version 0.8.0 there where no breaking changes. Every change was backward compatible and every functionality that was removed in v1.0 only triggers a deprecation warning in v0.10.

To upgrade from v0.x to v1 just update to 0.10.2 and resolve all deprecation warnings.

  1. Update your composer.json to «art4/json-api-client»: «^0.10.2»
  2. Make your code deprecation warnings free
  3. Upgrade your composer.json to «art4/json-api-client»: «^1.0» without breaking your app
use Art4\JsonApiClient\Exception\InputException; use Art4\JsonApiClient\Exception\ValidationException; use Art4\JsonApiClient\Helper\Parser; // The Response body from a JSON API server $jsonapiString = '>'; try < // Use this if you have a response after calling a JSON API server $document = Parser::parseResponseString($jsonapiString); // Or use this if you have a request to your JSON API server $document = Parser::parseRequestString($jsonapiString); > catch (InputException $e) < // $jsonapiString is not valid JSON > catch (ValidationException $e) < // $jsonapiString is not valid JSON API >

Note: Using Art4\JsonApiClient\Helper\Parser is just a shortcut for directly using the Manager.

$document implements the Art4\JsonApiClient\Accessable interface to access the parsed data. It has the methods has($key) , get($key) and getKeys() .

// Note that has() and get() have support for dot-notated keys if ($document->has('meta.info')) < echo $document->get('meta.info'); // "Testing the JsonApiClient library." > // you can get all keys as an array var_dump($document->getKeys()); // array( // 0 => "meta" // )

JsonApiClient can be used as a validator for JSON API contents:

use Art4\JsonApiClient\Helper\Parser; $wrong_jsonapi = ',"meta":>'; if ( Parser::isValidResponseString($wrong_jsonapi) ) < // or Parser::isValidRequestString($wrong_jsonapi) echo 'string is valid.'; > else < echo 'string is invalid json api!'; > // echoes 'string is invalid json api!'

Need more functionality? Want to directly inject your model? Easily extend JsonApiClient with the Factory.

Please see CHANGELOG for more information what has changed recently.

Please feel free to fork and sending Pull Requests. This project follows Semantic Versioning 2 and PSR-2.

GPL3. Please see License File for more information.

About

👷‍♀️ A PHP Library to handle the request or response body from a JSON API server.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

JSON API Client for PHP that adheres to the JSON API 1.0 spec

License

joeybeninghove/json-api-php-client

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

This library is an opinionated, resource-based JSON API client for PHP that strives to adhere to the offical JSON API 1.0 spec.

You can install it via Composer. Run the following command:

composer require cloudswipe/json-api-php-client

To use the bindings, use Composer’s autoload:

require_once('vendor/autoload.php');
  • baseUrl is specified as the root URL used when interacting with the API.
  • url is the specific part of the URL for the current resource
  • type is the JSON API type for the current resource
use JsonApiClient\Resource; class Invoice extends Resource < public function __construct() < parent::__construct( "https://api.site.com/v1/", // base URL "invoices" // type ) > >

Set up HTTP Authentication

The username is required, but the password is optional and defaults to blank.

If you’re using a typical API key over HTTP Authentication, here is an example of using a base class to abstract that away.

class Base extends Resource < public function __construct($type) < parent::__construct("http://api.site.come/v1/", $type); > public static function setApiKey($apiKey) < parent::auth($apiKey); > > class Invoice extends Base < public function __construct() < parent::__construct("invoices"); > > Base::setApiKey("some secret key"); $invoices = Invoice::getAll();
$invoice = Invoice::create([ "description" => "T-Shirt", "total" => 10.95 ]);

Update a resource with partial updates. This uses the PATCH method under the hood. See Where’s PUT?.

$invoice = Invoice::update("invoice_123", [ "description" => "Blue T-Shirt" ]);
$invoice = Invoice::getOne("invoice_123");

About

JSON API Client for PHP that adheres to the JSON API 1.0 spec

Источник

Оцените статью