Download the PHP package rikudou/json-rpc-bundle without Composer

On this page you can find all versions of the php package rikudou/json-rpc-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package json-rpc-bundle

JSON-RPC bundle for Symfony.

This allows you to respond and handle JSON-RPC requests using modern php.

Both batch requests and single requests are supported.

Installation

Requires php 8 and Symfony 5.x.

composer require rikudou/json-rpc-bundle

Usage

Create a controller that will be handling the traffic, the controller is very simple and basically looks like this:

The JsonRpcRequest object is automatically injected based on current request and the JsonRpcResponder takes care of locating the correct method and providing response.

Creating methods

Creating methods is very simple and you have 3 options:

  1. use the Rikudou\JsonRpcBundle\Attribute\JsonRpcMethod attribute in a callable object (implementing __invoke())
  2. implement the \Rikudou\JsonRpcBundle\JsonRpc\JsonRpcMethod interface
  3. registering callables manually

Note that while the attribute and interface have the same name, the namespace is different.

Example with attribute

Or if you want to accept parameters:

If any other parameters are provided, an exception might be thrown, to avoid that you can add a variadic parameter that catches all other parameters (the name of the parameter doesn't matter):

Example with interface

You can also check for parameters:

Registering other callables

You can register other callables manually in a configuration file (for example config/packages/json_rpc.yaml).

Here's an example configuration:

These formats of callables are supported:

Note that the service name starts with @.

Working with request object

If you want to do some checks on the request object you can do so before passing it to the JsonRpcResponder service.

The JsonRpcRequest is a marker interface that doesn't contain any methods meaning you need to check yourself if it's an instance of JsonRpcSingleRequest or JsonRpcBatchRequest.

The JsonRpcSingleRequest object contains these methods:

The JsonRpcBatchRequest contains these methods:

In your controller you can also typehint the concrete class (JsonRpcSingleRequest or JsonRpcBatchRequest) but in that case you will get a TypeError when the other type of request arrives.

If you want to get the current request outside of a controller class, you will need to use the service JsonRpcRequestParser:

Working with response object

If you want to alter the response in your controller, you can call JsonRpcResponse's getJson() method which returns an array with the raw data that would be encoded to JSON.

You can check whether the response is a single one or batch one by checking for instance of JsonRpcSingleResponse and JsonRpcBatchResponse.


All versions of json-rpc-bundle with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
symfony/framework-bundle Version ^5.0
symfony/yaml Version ^5.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rikudou/json-rpc-bundle contains the following files

Loading the files please wait ....