waylandace/json-rpc-bundle

JSON-RPC 2.0 Server for Symfony

v3.1.2 2018-12-26 09:29 UTC

This package is auto-updated.

Last update: 2024-04-07 06:18:33 UTC


README

JSON-RPC 2.0 Server for Symfony

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require waylandace/json-rpc-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new NeoFusion\JsonRpcBundle\NeoFusionJsonRpcBundle(),
        );

        // ...
    }

    // ...
}

Step 3: Configure API methods

You can easily define methods in your configuration file (config/services.yaml):

services:
    App\Api\Auth:
        public: false
        tags:
          - { name: 'app.api.json_rpc', alias: 'auth' }
    

Step 4: Register the routes

Finally, register this bundle's routes by adding the following to your project's routing file:

# app/config/routes/neofusion_jsonrpc.yaml
neofusion_jsonrpc:
    resource: "@NeoFusionJsonRpcBundle/Controller/ServerController.php"
    prefix: /
    type: annotation

Step 5: Register compiler

# src/Kernel.php
    protected function build(ContainerBuilder $container)
    {
        $container->addCompilerPass(new JsonRpcPass());
    }