定制 eugenejenkins/json-rpc-server 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

eugenejenkins/json-rpc-server

最新稳定版本:v1.0.0

Composer 安装命令:

composer require eugenejenkins/json-rpc-server

包简介

A lightweight JSON-RPC server implementation in PHP.

README 文档

README

This project is a JSON-RPC server implemented in PHP 8.1. It adheres to the JSON-RPC 2.0 specification (RFC 7049). The server is built in a canonical way, following best practices for handling JSON-RPC requests.

Features

  • Complies with the JSON-RPC 2.0 standard.
  • Supports method registration and execution.
  • Structured exception handling for request processing.

Requirements

  • PHP 8.1 or higher
  • Composer

Installation

  1. Clone the repository:

    git clone git@github.com:EugeneJenkins/json-rpc-server.git
    cd json-rpc-server
  2. Install dependencies::

    composer install

Example Usage

$server = new Server;

$server->register('subtract', fn($minuend, $subtrahend) => $minuend - $subtrahend);
$server->register('add', fn($a, $b) => $a + $b);

$server->registerClass(Calculator::class);

$response = $server->execute();
$response->show();

To run the server locally, you can use the built-in PHP server:

php -S localhost:8008 index.php

How to Make Requests

You can send JSON-RPC requests to the server using any HTTP client (e.g., curl, Postman, etc.).

Example request:

curl -X POST http://localhost:8008 \
    -H "Content-Type: application/json" \
    -d '{
        "jsonrpc": "2.0",
        "method": "subtract",
        "params": {"minuend": 10, "subtrahend": 3},
        "id": 1
    }'

Example response:

{
    "jsonrpc": "2.0",
    "result": {
        "minuend": 10,
        "subtrahend": 3
    },
    "id": 1
}

Error Handling

If an error occurs during the execution of a request, the server will respond with a JSON-RPC error object, as specified in the JSON-RPC 2.0 specification.

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-05