Download the PHP package projectsaturnstudios/json-rpc without Composer
On this page you can find all versions of the php package projectsaturnstudios/json-rpc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download projectsaturnstudios/json-rpc
More information about projectsaturnstudios/json-rpc
Files in projectsaturnstudios/json-rpc
Package json-rpc
Short Description A Laravel package for implementing the Remote Procedure Call (RPC) protocol
License MIT
Informations about the package json-rpc
JSON-RPC Laravel Package
A Laravel package for implementing the JSON-RPC 2.0 protocol with elegant attribute-based routing and clean data handling.
Features
- 🚀 JSON-RPC 2.0 Compliant - Full implementation of the JSON-RPC 2.0 specification
- 🎯 Attribute-Based Routing - Clean, declarative method routing using PHP 8 attributes
- 📦 Laravel Data Integration - Powered by Spatie Laravel Data for robust data handling
- 🛡️ Comprehensive Error Handling - Standard JSON-RPC error codes and custom exceptions
- 🎭 Facade Support - Laravel-style facade for easy access
- 🔧 Extensible Architecture - Easy to extend with custom controllers and middleware
- 📝 Type Safety - Full PHP 8.2+ type declarations throughout
- 🛣️ Route File Integration - Familiar Laravel routing patterns with
routes/rpc.php
Installation
Install the package via Composer:
The package will automatically register itself via Laravel's auto-discovery.
Quick Start
1. Create an RPC Controller
2. Register Your Controllers
Create a routes/rpc.php
file in your Laravel application:
The package automatically loads this file and registers all your RPC methods.
3. Dispatch RPC Requests
Usage Examples
Basic Request/Response
Error Handling
Notifications (Fire and Forget)
Advanced Controller Example
Route Registration
Using routes/rpc.php (Recommended)
Create a routes/rpc.php
file in your Laravel application:
Alternative: Manual Registration
If you prefer to register methods manually in a service provider:
Configuration
The package includes a basic configuration file. You can publish it with:
The configuration file config/rpc.php
allows you to customize:
API Reference
RPCRequest
RPCResponse
Note: A response must contain either a result
or an error
, but not both.
RPCNotification
RPCErrorObject
Error Codes
Code | Constant | Description |
---|---|---|
-32700 | PARSE_ERROR | Invalid JSON was received |
-32600 | INVALID_REQUEST | The JSON sent is not a valid Request object |
-32601 | METHOD_NOT_FOUND | The method does not exist / is not available |
-32602 | INVALID_PARAMS | Invalid method parameter(s) |
-32603 | INTERNAL_ERROR | Internal JSON-RPC error |
-32000 | SERVER_ERROR | Server error |
Method Routing
The package supports hierarchical method routing:
math
→MathController::handle()
math/add
→MathController::add()
weather/current
→WeatherController::current()
api/v1/calculator
→MathController::handle()
api/v1/calculator/add
→MathController::add()
Artisan Commands
List Registered Methods
You can view all registered RPC methods using the provided Artisan command:
This will display a formatted list of all registered methods and their corresponding controllers:
This command is useful for:
- Debugging method registration issues
- Viewing the current state of your RPC routing
- Documenting available methods for your team
Testing
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
The MIT License (MIT). Please see License File for more information.
About Project Saturn Studios
This package is developed and maintained by Project Saturn Studios.
Need help? Check out the examples directory for more usage examples, or create an issue if you run into any problems!
All versions of json-rpc with dependencies
ext-json Version *
spatie/laravel-data Version ^4.11
lorisleiva/laravel-actions Version ^2.6