PHPackages                             rds/jrf - 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. [Framework](/categories/framework)
4. /
5. rds/jrf

ActiveLibrary[Framework](/categories/framework)

rds/jrf
=======

JSON-RPC 2.0 Framework

1.1.1(11y ago)241MITPHPPHP ~5.5

Since Mar 4Pushed 11y ago45 watchersCompare

[ Source](https://github.com/rambler-digital-solutions/JRF)[ Packagist](https://packagist.org/packages/rds/jrf)[ RSS](/packages/rds-jrf/feed)WikiDiscussions master Synced 4d ago

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

JSON RPC Framework (JRF)
========================

[](#json-rpc-framework-jrf)

[![Build Status](https://camo.githubusercontent.com/acd1e7ee1ca49f2d7332ea07948726d049f41c8cca3704460d60aaf27f589409/68747470733a2f2f7472617669732d63692e6f72672f72616d626c65722d6469676974616c2d736f6c7574696f6e732f4a52462e737667)](https://travis-ci.org/rambler-digital-solutions/JRF)

**JRF** is a **JSON-RPC over HTTP** data providing framework. Simple component-based architecture allow you to fast and easy web service developing. From the box (as-is) **JRF** supports a controller/action factory, input interface (PhpInput by default), and MiddleWare request checking.

SchemaChecker interface allow to hint-and-check incoming params for any method provided by yours application service.

Smart-fault interface is very easy to use. You don't need to care about anything low-level lifecycle catchers and response result builders. Just raise and see =)

Outside of the box, you can create a powerful controller-based application service with controller factory.

Usage example
=============

[](#usage-example)

```
use \jrf\JRF;
$service = new JRF();

$service->controller()->handleMethod('method',
    function($param_1, $param_2, JRF $app, $request_id) {
        return $param_1 + $param_2
    });

$service->listen();
```

Just post JSON on it:

```
{
    "jsonrpc": "2.0",
    "id": 100,
    "method": "method",
    "params": [1, 3]
}
```

Overriding input interface
==========================

[](#overriding-input-interface)

If php://input is a bad way for you, you can create your own input:

```
use jrf\http\Input;

class MyInput extends Input
{
    private $input;

    public function __construct($input)
    {
        $this->input = $input;
    }

    public function read()
    {
        return $this->input;
    }
}
```

And override default like this:

```
// ..... service init
use MyInput;
$input = new MyInput($_POST['json']);
$service->request()->setInputProvider($input);
```

All done =) Your provider will work fine inside JRF ecosystem.

Create access middleware
========================

[](#create-access-middleware)

In "captain obvious" opinion, all available private service must have access provisioning module. Let's code-in it:

```
use \jrf\middleware\Base;
use \jrf\fault\ServerError;

class AccessMiddleware extends Base
{
	private $ip_list=[];
	public function __construct(array $ip_list) {
		$this->ip_list = $ip_list;
	}

	public function call()
	{
		$info = $this->app->request()->info();
		$ip   = $info['ip_address'];

		if (!in_array($ip, $this->ip_list)) {
		    ServerError::raise('access error');
		}

		$this->next->call();
	}
}
```

Let's add our middleware into service:

```
// ... service init
use AccessMiddleware;

$list_allowed_ip = ['127.0.0.1'];

$service->add(new AccessMiddleware($list_allowed_ip));
```

Create custom controller factory
--------------------------------

[](#create-custom-controller-factory)

Simple and easy way to create factory - use namespace-based action provider.

```
use jrf\controller\Base;
use jrf\fault\MethodNotFound;

class MyControllerFactory extends Base
{
    public function runMethodWithArgs($method, array $args =[], $request_id=0)
    {
        // fall-back if want to use closure-based methods
        if ($this->isHandledMethod($method)) {
            return parent::runMethodWithArgs($method, $args, $request_id);
        }

        // now try to create action class
        if (strpos('.', $method)===false) {
            MethodNotFound::raise();
        }

        list($group, $action) = explode('.', $method);

        $class_name = sprint_f("\my\action\namespace\%s\%s", strtolower($group), ucfirst($action));

        if (!class_exists($class_name)) {
            MethodNotFound::raise();
        }

        $action = new $class_name($this->app());

        if (!is_callable([$action, 'run'])) {
            MethodNotFound::raise();
        }

        return $action->run();
    }
}
```

Implementation:

```
// .... service init
use MyControllerFactory;
$factory = new MyControllerFactory;
$service->controller($factory);
```

Incoming params hinting/checking
--------------------------------

[](#incoming-params-hintingchecking)

For example, json was posted is:

```
{
    "jsonrpc":"2.0",
    "id":120,
    "method":"test",
    "params":{
        "a":11,
        "b":10
    }
}
```

Rules:

- a &gt; 0
- b &gt; 0
- a is INT
- b is INT
- a REQUIRED
- b REQUIRED

Implementation

```
use jrf\json\Schema;

$params_definition = [
    'a' => [
        'type' => Schema::TYPE_INT,
        'definition' => Schema::DEFINITION_REQUIRED,
        'expression' => function ($v) { return intval($v) > 0; }
    ],
    'b' => [
        'type' => Schema::TYPE_INT,
        'definition' => Schema::DEFINITION_REQUIRED,
        'expression' => function ($v) { return intval($v) > 0; }
    ],
];

$schema = new Schema($params_definition);
$service->controller()->setSchemaForMethod('test', $schema);
```

Configuration container
-----------------------

[](#configuration-container)

Configuration Container instantiated Inside JRF constructor method with options passed inside it. To access container JRF provide method named "config", config access examples:

```
use jrf\JRF;

$options = [
    'app.debug' => true,
    'app.secret' => 'secret'
];

$service = new JRF($options);

// return: null
$val = $service->config('unknown-option');

// return default defined value: 123
$val = $service->config('unknown-option', 123);

// return true
$val = $service->config('app.debug');
$val = $service->config('app.debug', false);
$val = $service->config()->get('app.debug');
$val = $service->config()->{'app.debug'};
$val = $service->config()['app.debug'];
```

Client usage
------------

[](#client-usage)

```
$client = new Client("http://json-rpc.server/");

$pipe = $client->createPipe();

$batch = $client->createBatch();
$m1_id = $batch->append($client->method('m1', [1,2,3]));
$m2_id = $batch->append($client->method('m2'));
$m3_id = $batch->append($client->method('m3'));

$pipe->add('batch', $batch);
$pipe->add('news', $client->method('news.search', ['limit'=>50]));
$pipe->add('users', $client->method('users.all', ['limit'=>10]));

$response = $client->executePipe($pipe);

$m1 = $response['batch'][$m2_id];

var_dump($m1->getResult());
var_dump($client->getTotalTime());
```

Unit Tests
----------

[](#unit-tests)

```
cd path/to/jrf-root
php composer.phar update --dev
vendor/bin/phpunit
```

No-HTTP Usage
-------------

[](#no-http-usage)

If that really needed, JRF allow to handle custom input interface without any listeners. By this way JRF is not provide response output. However, if you need to use couple of providers both, you can run service by add **$service-&gt;listen()**.

```
// input interface from example
use MyInput;

$payload = ["jsonrpc"=>"2.0", "id"=>1, "method"=>"my.method"];
$input   = new MyInput(json_encode($payload));

// ... defining service

$result_string = $service->handleInputProvider($input);
$result_array  = json_decode($result_string, true);

// if HTTP listener needed
$service->listen();
```

License
-------

[](#license)

Copyright (c) 2014 Rambler&amp;Co

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% 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

Every ~1 days

Total

3

Last Release

4089d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/150420?v=4)[Ruslan Sharipov](/maintainers/Serafim)[@serafim](https://github.com/serafim)

---

Top Contributors

[![MadFaill](https://avatars.githubusercontent.com/u/2902608?v=4)](https://github.com/MadFaill "MadFaill (2 commits)")[![A](https://avatars.githubusercontent.com/u/1410106?v=4)](https://github.com/A "A (1 commits)")

---

Tags

microframeworkjson-rpc

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rds-jrf/health.svg)

```
[![Health](https://phpackages.com/badges/rds-jrf/health.svg)](https://phpackages.com/packages/rds-jrf)
```

###  Alternatives

[slim/slim-skeleton

A Slim Framework skeleton application for rapid development

1.6k458.7k6](/packages/slim-slim-skeleton)[clue/framework-x

Framework X – the simple and fast micro framework for building reactive web applications that run anywhere.

936736.7k8](/packages/clue-framework-x)[vlucas/bulletphp

A heierarchical resource-oriented micro-framework built on nested closures instead of route-based callbacks

41949.9k1](/packages/vlucas-bulletphp)[chubbyphp/chubbyphp-framework

A minimal, highly performant middleware PSR-15 microframework built with as little complexity as possible, aimed primarily at those developers who want to understand all the vendors they use.

13544.4k4](/packages/chubbyphp-chubbyphp-framework)[noodlehaus/dispatch

a micro-routing library for PHP

5371.4k2](/packages/noodlehaus-dispatch)[pinoco/pinoco

Web site development framework using PHP and (mainly) PHPTAL

428.6k](/packages/pinoco-pinoco)

PHPackages © 2026

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