hecsedli/cakephpjsonrpcserver

CakePHP 3.x JSON-RPC server

0.3 2018-05-24 21:23 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:21:11 UTC


README

CakePHP 3.x JSON-RPC server

Original idea: James Watts https://github.com/jameswatts/cake-jsonrpc

Requirements

  • CakePHP 3.6+
  • PHP 5.6+

Installation

You can install using composer.

composer require hecsedli/cakephpjsonrpcserver
// config/bootstrap.php

Plugin::load('JSONRPCServer', ['bootstrap' => true]);

Implementation

Add the component to your controller

public $components = ["JSONRPCServer.JsonrpcServer"];
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);
	}
);

JSON request

{
	"jsonrpc": "2.0", 
	"method": "user", 
	"params": {
		"userId": 5
	}, 
	"id": "test"
}