PHPackages                             jameswatts/cake-jsonrpc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. jameswatts/cake-jsonrpc

ActiveCakephp-plugin[Parsing &amp; Serialization](/categories/parsing)

jameswatts/cake-jsonrpc
=======================

JSON-RPC plugin for CakePHP

1.0.0(12y ago)277456[1 PRs](https://github.com/jameswatts/cake-jsonrpc/pulls)MITPHPPHP &gt;=5.3.0

Since Oct 26Pushed 9y ago6 watchersCompare

[ Source](https://github.com/jameswatts/cake-jsonrpc)[ Packagist](https://packagist.org/packages/jameswatts/cake-jsonrpc)[ Docs](https://github.com/jameswatts/cake-jsonrpc)[ RSS](/packages/jameswatts-cake-jsonrpc/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (3)Used By (0)

JSON-RPC Plugin
===============

[](#json-rpc-plugin)

The **Jsonrpc** plugin for *CakePHP* provides server and client implementations of [JSON-RPC](http://www.jsonrpc.org).

Requirements
------------

[](#requirements)

- CakePHP 2+
- PHP 5.3+

Installation
------------

[](#installation)

To use the plugin simply include it in your application's "app/Plugin" directory, and load it in the "app/Config/bootstrap.php" file.

```
CakePlugin::load('Jsonrpc');
```

The above code is *not* required if you're already using `CakePlugin::loadAll()` to load all plugins.

Implementation
--------------

[](#implementation)

### Server

[](#server)

The [Jsonrpc.Server](Controller/Component/ServerComponent.php) component allows a *CakePHP* application to listen for incoming **JSON-RPC** calls. The actions listening are defined in the "listen" option of the component's settings. To add the component to your controller acting as the end-point include it in your *$components* property, for example:

```
public $components = array(
	'Jsonrpc.Server' => array(
		'listen' => array('example') // will process JSON-RPC requests sent to this action
	)
);
```

Once available, the server will now listen on the actions specified in the "listen" setting. When a call is made to one of these actions, and assuming no error occurs previously in the processing of the request, the call will be delegated to the controller method defined in the "method" property of the JSON request object. This method will receive a single argument, which is the JSON request object received by the server. The value returned by this method will be JSON encoded, and sent back to the client in the "result" property of the JSON response object.

```
public function user($request) {
	if (isset($request->params->userId)) {
		return $this->User->findById($request->params->userId);
	} else {
		throw new Exception('No user ID was specified', 123);
	}
);
```

In order to send an error as the response you need only throw an *Exception* in your controller's method. This will be caught by the **Server** component and processed as a JSON error object.

### Client

[](#client)

The [Jsonrpc.Client](Controller/Component/ClientComponent.php) component allows a *CakePHP* application to make **JSON-RPC** requests to a server. To use the component add it to the *$components* property of your controller, for example:

```
public $components = array('Jsonrpc.Client');
```

From your actions you can now make requests using the **Client** component. To do so, first create a JSON request object, and then send it to the **JSON-RPC** server.

```
public function getUser() {
	// create a JSON request object
	$request = $this->Client->createJsonRequest('user', array('userId' => 7));
	// send the request to the server and return the result
	return $this->Client->sendJsonRequest($request, array('host' => 'example.com', 'path' => '/api/call'));
);
```

Keep in mind that if a JSON error object is returned from the server this will be thrown as a *CakeException* in your application.

You can also send batch requests to a server by specifying multiple JSON request objects in an array, for example:

```
public function getAllTheThings() {
	// create multiple JSON request objects in an array
	$batch = array(
		$this->Client->createJsonRequest('hat', array('hatId' => 11)),
		$this->Client->createJsonRequest('jacket', array('jacketId' => 55)),
		$this->Client->createJsonRequest('shoes', array('shoesId' => 73))
	);
	// send the array of requests to the server and return the results as an array
	return $this->Client->sendJsonRequest($batch);
);
```

When sending batch requests, if one of the request returns a JSON error object a *CakeException* will not be thrown, as the error object is returned within the array. Also, be aware that the order of the JSON response objects may not be coherent with the order of the requests sent, so always use the ID to determine the response corresponding with your request.

Documentation
-------------

[](#documentation)

For a full reference on the internals of the **JSON-RPC** protocol/transport see the [specification](http://www.jsonrpc.org/specification).

Support
-------

[](#support)

For support, bugs and feature requests, please use the [issues](https://github.com/jameswatts/cake-jsonrpc/issues) section of this repository.

Contributing
------------

[](#contributing)

If you'd like to contribute new features, enhancements or bug fixes to the code base just follow these steps:

- Create a [GitHub](https://github.com/signup/free) account, if you don't own one already
- Then, [fork](https://help.github.com/articles/fork-a-repo) the [Jsonrpc](https://github.com/jameswatts/cake-jsonrpc) plugin repository to your account
- Create a new [branch](https://help.github.com/articles/creating-and-deleting-branches-within-your-repository) from the *develop* branch in your forked repository
- Modify the existing code, or add new code to your branch, making sure you follow the [CakePHP Coding Standards](http://book.cakephp.org/2.0/en/contributing/cakephp-coding-conventions.html)
- Modify or add [unit tests](http://book.cakephp.org/2.0/en/development/testing.html) which confirm the correct functionality of your code (requires [PHPUnit](http://www.phpunit.de/manual/current/en/installation.html) 3.5+)
- Consider using the [CakePHP Code Sniffer](https://github.com/cakephp/cakephp-codesniffer/tree/1.x) to check the quality of your code
- When ready, make a [pull request](http://help.github.com/send-pull-requests/) to the main repository

There may be some discussion reagrding your contribution to the repository before any code is merged in, so be prepared to provide feedback on your contribution if required.

A list of contributors to the **Jsonrpc** plugin can be found [here](https://github.com/jameswatts/cake-jsonrpc/contributors).

Licence
-------

[](#licence)

Copyright 2013 James Watts (CakeDC). All rights reserved.

Licensed under the MIT License. Redistributions of the source code included in this repository must retain the copyright notice found in each file.

Acknowledgements
----------------

[](#acknowledgements)

Thanks to [Larry Masters](https://github.com/phpnut) and [everyone](https://github.com/cakephp/cakephp/contributors) who has contributed to [CakePHP](http://cakephp.org), helping make this framework what it is today. Also, to the [JSON-RPC Working Group](https://groups.google.com/forum/#!forum/json-rpc), for their hard work and dedication to the specification.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4578d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d13e13867abbe5c99c3fa0d4ab86472d15bd049212a9737a26487ef320347599?d=identicon)[jameswatts](/maintainers/jameswatts)

---

Top Contributors

[![ravage84](https://avatars.githubusercontent.com/u/625761?v=4)](https://github.com/ravage84 "ravage84 (1 commits)")

---

Tags

jsoncakephpjsonrpcjson-rpccake

### Embed Badge

![Health badge](/badges/jameswatts-cake-jsonrpc/health.svg)

```
[![Health](https://phpackages.com/badges/jameswatts-cake-jsonrpc/health.svg)](https://phpackages.com/packages/jameswatts-cake-jsonrpc)
```

###  Alternatives

[datto/json-rpc

Fully unit-tested JSON-RPC 2.0 for PHP

1951.3M14](/packages/datto-json-rpc)[wa72/jsonrpc-bundle

JSON-RPC server for Symfony: exposes services registered in the service container as JSON-RPC webservices

3164.1k](/packages/wa72-jsonrpc-bundle)[cranetm/yii2-json-rpc-2.0

JSON RPC 2.0 for Yii2 strict type validation of request and response data

2679.6k1](/packages/cranetm-yii2-json-rpc-20)[nizsheanez/yii2-json-rpc

A lightweight JsonRpc Server and Client for PHP

2034.0k](/packages/nizsheanez-yii2-json-rpc)[andreyryabin/sprint.editor

Редактор для контент-менеджеров

485.6k](/packages/andreyryabin-sprinteditor)[tinywan/rpc

simple rpc service for webman plugin

193.5k](/packages/tinywan-rpc)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
