Skip to content

Latest commit

 

History

History
70 lines (63 loc) · 3.35 KB

README.md

File metadata and controls

70 lines (63 loc) · 3.35 KB

Speech

JSON-RPC 2.0 for PHP

Build Status Latest Stable Version

Bundle for JSON-RPC 2.0. You can use as standalone library. Or with Symfony.

Features

Use

Symfony

  • Install package: composer require zored/speech.
  • Add bundle new Zored\SpeechBundle\ZoredSpeechBundle() to your Symfony kernel app/AppKernel.php.
  • Add route to default endpoint: routing.yml:
    json_rpc:
        defaults: { _controller: ZoredSpeechBundle:Default:jsonRpc }
        methods: [POST] # Or GET for Zored RPC.
        path: /json-rpc
  • Add service with your JSON-RPC methods in services.yml:
    services:
        your.service:
            # Replace with your own class:
            class: 'Zored\SpeechBundle\Test\JsonRpc\Greeter'
  • Allow this service to run in default controller via parameters.yml:
    parameters:
      zored.speech.controller.context.service_ids: ['your.service']
  • Clear caches.
  • Test:
    curl http://example.com/json-rpc/ \
        --data '{"id":"1", "method":"your.service:greet", "params":{"person":{"name":"bob","age":19}},"jsonrpc":"2.0"}'

Standalone library

  • See example in web/index.php
  • Run there server with php -S 127.0.0.1:8080
  • Test:
    curl http://127.0.0.1:8080 \
        --data '{"id":"1", "method":"your.service:greet", "params":{"person":{"name":"bob","age":19}},"jsonrpc":"2.0"}'

What's next?

Inside

  • Your request JSON string goes to endpoint which handles it and returns Symfony response.
  • Endpoint chooses which request passer can pass JSON string to request handler.
    • There are single for {} and batch for [{},{}] passers enabled by default.
  • Request passer also deserializes JSON to object and validates it.
  • Request passer passes request object to request handler that pushes request somewhere to get response.
  • Request then passed back and serialized to array.

Events

You can see available events here.