PHP code example of haskel / grpc-web-bundle

1. Go to this page and download the library: Download haskel/grpc-web-bundle 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/ */

    

haskel / grpc-web-bundle example snippets


return [
    // ...
    Haskel\GrpcWebBundle\GrpcWebBundle::class => ['all' => true],
];



namespace App\Controller\Grpc;

use App\Grpc\Api\PingRequest;
use App\Grpc\Api\PingResponse;
use Haskel\GrpcWebBundle\Attribute as Grpc;

#[Grpc\Service('PingService', package: 'grpc.api')]
class PingService
{
    public function Ping(PingRequest $request): PingResponse
    {
        $message = $request->getMessage();
        
        $response = new PingResponse();
        $response->setMessage("pong:" . $message);
        
        return $response;
    }
}
bash
protoc --php_out=src --grpc-web_out=mode=grpcwebtext:src --proto_path=config/proto