PHP code example of bpartner / jsonrpc

1. Go to this page and download the library: Download bpartner/jsonrpc library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bpartner / jsonrpc example snippets


 protected string|array $middlewares = 'guest';
//or
 protected string|array $middlewares = [
    MyMiddleware::class,
    SecondMiddleware::class
];
 bash
php artisan make:rpc MyHandler 
 php
public function handle(): array
{
    $myData = MyBusinessLogicClass::make($this->params);

    return ['data' => $myData];
}
 php
protected function rule(): array
{
    return [
        'param1' => '
 php
class AuthToken
{
    public function handle(Request $request, Closure $next)
    {
        if ($request->header('x-auth-token') !== config('jsonrpc.token')) {
            return  response()->json([
                'status' => 'error',
                'code' => 401,
                'message' => 'Unauthorized',
            ]);
        }
        return $next($request);
    }
}