JSON-RPC server for Laravel | Laravel news



JSON RPC Server is a package to build JSON-RPC 2.0 API using the Laravel framework. The package is designed to integrate a lightweight and easy-to-use remote procedure call protocol:

1namespace AppHttpProcedures;

2 

3use SajyaServerProcedure;

4 

5class TennisProcedure extends Procedure

6{

7 /**

8 * The name of the procedure that will be

9 * displayed and taken into account in the search

10 */

11 public static string $name = 'tennis';

12 

13 /**

14 * Execute the procedure.

15 *

16 * @return string

17 */

18 public function ping()

19 {

20 return 'pong';

21 }

22}

Considering the above procedure class, this package allows you to easily call it using the following route:

1use AppHttpProceduresTennisProcedure;

2 

3Route::rpc('/v1/endpoint', [TennisProcedure::class])

4 ->name('rpc.endpoint');

Here is an example of calling the endpoint:

1curl 'http://127.0.0.1:8000/api/v1/endpoint'

2 --data-binary '{"jsonrpc":"2.0","method":"[email protected]","id":1}'

3 

4# Result: {"id":"1","result":"pong","jsonrpc":"2.0"}

By using JSON-RPC with this package, you can batch process a job that allows you to optimize your application by combining multiple requests into a single JSON object:

1[

2 {

3 "jsonrpc": "2.0",

4 "method": "[email protected]",

5 "params": "...",

6 "id": 1

7 },

8 {

9 "jsonrpc": "2.0",

10 "method": "[email protected]",

11 "params": "...",

12 "id": 2

13 }

14]

This package can also facilitate the creation of a JSON RPC API with the following features:

  • Authentication
  • Data validation in procedures
  • API documentation generation
  • Parameter binding resolution in procedures, including model binding
  • Testing the functionality of JSON RPC procedures
  • Gzip compression middleware

You can learn more about this package, get full installation instructions, and view the source code on GitHub. This package also useful Documentation to start.



Source link

Previous Who was Les Paul? - Official website for musicians and inventors launches
Next Lineage W takes off across the world on November 4