All Projects → graze → Guzzle Jsonrpc

graze / Guzzle Jsonrpc

Licence: mit
JSON-RPC 2.0 client for Guzzle

Labels

Projects that are alternatives of or similar to Guzzle Jsonrpc

PhpBotFramework
A framework for Telegram Bot API written in PHP.
Stars: ✭ 56 (-35.63%)
Mutual labels:  guzzle
The-PHP-Workshop
A New, Interactive Approach to Learning PHP
Stars: ✭ 30 (-65.52%)
Mutual labels:  guzzle
Guzzlette
🌀 Guzzle integration into Nette Framework (@nette)
Stars: ✭ 19 (-78.16%)
Mutual labels:  guzzle
eventbrite
A lightweight PHP library for interacting with version 3 of the Eventbrite API.
Stars: ✭ 20 (-77.01%)
Mutual labels:  guzzle
http-constants
The missing PHP constants for HTTP header fields
Stars: ✭ 19 (-78.16%)
Mutual labels:  guzzle
Guzzle Cache Middleware
A HTTP Cache for Guzzle 6. It's a simple Middleware to be added in the HandlerStack.
Stars: ✭ 325 (+273.56%)
Mutual labels:  guzzle
guzzle-log-middleware
A Guzzle middleware to log request and responses automatically
Stars: ✭ 61 (-29.89%)
Mutual labels:  guzzle
Bof
The HTTP client for humans
Stars: ✭ 76 (-12.64%)
Mutual labels:  guzzle
guzzlehttp-cloudflare
Guzzle middleware to pass through Cloudflare protection
Stars: ✭ 31 (-64.37%)
Mutual labels:  guzzle
Guzzle
Guzzle, an extensible PHP HTTP client
Stars: ✭ 21,384 (+24479.31%)
Mutual labels:  guzzle
guzzle6-bundle
Integrates Guzzle 6 into your Symfony application
Stars: ✭ 11 (-87.36%)
Mutual labels:  guzzle
AkamaiOPEN-edgegrid-php-client
PHP client library for Akamai {OPEN} EdgeGrid Authentication scheme (based on Guzzle)
Stars: ✭ 38 (-56.32%)
Mutual labels:  guzzle
Ganesha
🐘 A Circuit Breaker pattern implementation for PHP applications.
Stars: ✭ 384 (+341.38%)
Mutual labels:  guzzle
GuzzleBundleOAuth2Plugin
OAuth2 Plugin for GuzzleBundle
Stars: ✭ 13 (-85.06%)
Mutual labels:  guzzle
Ean Client
PHP client for consuming the EAN Hotel API, based on Guzzle
Stars: ✭ 13 (-85.06%)
Mutual labels:  guzzle
jacky
🐄 HTTP JSON API Client for Laravel & Lumen
Stars: ✭ 17 (-80.46%)
Mutual labels:  guzzle
Sapient
Secure API Toolkit
Stars: ✭ 308 (+254.02%)
Mutual labels:  guzzle
Async Soap Guzzle
An asynchronous SOAP client build on top of Guzzle.
Stars: ✭ 78 (-10.34%)
Mutual labels:  guzzle
Phlack
Slack Integrations for PHP
Stars: ✭ 53 (-39.08%)
Mutual labels:  guzzle
Eightpointsguzzlebundle
⛽️ Integrates Guzzle 6.x, a PHP HTTP Client, into Symfony
Stars: ✭ 407 (+367.82%)
Mutual labels:  guzzle

Guzzle JSON-RPC

Master branch build status Coverage Status Quality Score Published version PHP ~5.5 MIT Licensed

This library implements JSON-RPC 2.0 for the Guzzle HTTP client. We try to support all commonly used versions of Guzzle including:

It can be installed in whichever way you prefer, but we recommend Composer.

{
    "require": {
        "graze/guzzle-jsonrpc": "~3.0"
    }
}

Documentation

<?php
use Graze\GuzzleHttp\JsonRpc\Client;

// Create the client
$client = Client::factory('http://localhost:8000');

// Send a notification
$client->send($client->notification('method', ['key'=>'value']));

// Send a request that expects a response
$client->send($client->request(123, 'method', ['key'=>'value']));

// Send a batch of requests
$client->sendAll([
    $client->request(123, 'method', ['key'=>'value']),
    $client->request(456, 'method', ['key'=>'value']),
    $client->notification('method', ['key'=>'value'])
]);

Async requests

Asynchronous requests are supported by making use of the Guzzle Promises library; an implementation of Promises/A+.

<?php
use Graze\GuzzleHttp\JsonRpc\Client;

// Create the client
$client = Client::factory('http://localhost:8000');

// Send an async notification
$promise = $client->sendAsync($client->notification('method', ['key'=>'value']));
$promise->then(function () {
    // Do something
});

// Send an async request that expects a response
$promise = $client->sendAsync($client->request(123, 'method', ['key'=>'value']));
$promise->then(function ($response) {
    // Do something with the response
});

// Send a batch of requests
$client->sendAllAsync([
    $client->request(123, 'method', ['key'=>'value']),
    $client->request(456, 'method', ['key'=>'value']),
    $client->notification('method', ['key'=>'value'])
])->then(function ($responses) {
    // Do something with the list of responses
});

Throw exception on RPC error

You can throw an exception if you receive an RPC error response by adding the option [rpc_error => true] in the client constructor.

<?php
use Graze\GuzzleHttp\JsonRpc\Client;
use Graze\GuzzleHttp\JsonRpc\Exception\RequestException;

// Create the client with the `rpc_error`
$client = Client::factory('http://localhost:8000', ['rpc_error'=>true]);

// Create a request
$request = $client->request(123, 'method', ['key'=>'value']);

// Send the request
try {
    $client->send($request);
} catch (RequestException $e) {
    die($e->getResponse()->getRpcErrorMessage());
}

Contributing

We accept contributions to the source via Pull Request, but passing unit tests must be included before it will be considered for merge.

~ $ make deps
~ $ make lint test

License

The content of this library is released under the MIT License by Nature Delivered Ltd.

You can find a copy of this license at mit or in LICENSE

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].