Download the PHP package aicrion/json-rpc without Composer

On this page you can find all versions of the php package aicrion/json-rpc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package json-rpc

Aicrion\JsonRpc

A modern, attribute-driven JSON-RPC 2.0 server library for PHP 8.2+.

Full documentation (installation, every feature, API reference) lives in docs/index.md -- built to be published on GitHub Pages. This README is a concise overview and quick-start reference.

Architecture

Unlike classic dispatcher-style RPC libraries, this library is built as a pipeline of independent stages, similar in spirit to HTTP middleware stacks. Every request flows through the same fixed sequence:

Every stage implements the same Pipeline\Stage interface, so the pipeline can be extended (via withMiddleware()) without ever touching the kernel's internals.

Requirements

Installation

Running tests

Run a single test:

Quick start

Feature overview

Namespaced handlers

Every handler declares its own namespace via #[RpcHandler('math')], #[RpcHandler('account')], etc. Methods become reachable as math.add, account.balance, and any number of handlers/namespaces can be registered on the same kernel without colliding (a duplicate qualified name throws at build time).

Automatic protected methods

Instead of guarding each method by hand, annotate the whole handler class:

The registry resolves protection once, at registration time, so AuthorizationStage never needs per-method wiring. The actual yes/no decision is delegated to any AuthorizationGate you provide via withAuthorizationGate() (defaults to fail-closed, denying every protected method).

Auto-discovery and lazy loading

No handler is ever instantiated until one of its methods is actually invoked -- regardless of which registration strategy you use:

Two ways to avoid the cost of scanning a directory on every request:

Strategy Filesystem scan Instantiation
withHandler() / withHandlers() none immediate (eager)
withHandlerClass() none on first invocation
withDiscoveredHandlers() once per build() on first invocation
withDiscoveredHandlers(cacheFile: ...) once ever on first invocation
withResolvedHandlers() never on first invocation

Handlers needing constructor dependencies can be built through any PSR-11 container via ContainerHandlerFactory, passed to any of the lazy registration methods above.

Batch requests (JSON-RPC 2.0 spec compliant)

dispatchJson() auto-detects whether the raw body is a single request object or a batch array and responds accordingly.

Custom middleware stages

Plug any Stage implementation into the pipeline, right after authorization and before parameter binding:

Invocation listeners

Observe every call without touching the pipeline:

Listeners fire around InvokeHandlerStage only -- a cache hit never triggers them, since the real handler method was never called.

Caching with pluggable backends

Annotate any method with #[Cacheable] to memoize its result. Pick any CacheStore implementation that fits your deployment:

Store Scope Use case
InMemoryCacheStore single request/process tests, CLI scripts
FileCacheStore single server, cross-request no external cache service available
ApcuCacheStore shared memory across PHP-FPM workers single-server web apps
RedisCacheStore distributed multi-server / cluster deployments
NullCacheStore none (default) caching disabled

Cache keys are derived from the method name and bound arguments via CacheKeyBuilder (default: DefaultCacheKeyBuilder), also swappable with withCacheKeyBuilder().

Rate limiting, local or distributed

RateLimitStage depends on the RateLimitStore abstraction, so the exact same middleware works identically on one server or across a cluster:

Returning custom errors from a handler

Throwing a plain exception inside a handler is always wrapped into a generic -32000 error, protecting clients from internal stack traces. To return a specific code/message/data for an expected business failure, throw Exception\RpcErrorException instead:

This propagates untouched to the client, while any other, unexpected exception still gets wrapped as a generic internal error. Reserve custom codes below -32000 to avoid colliding with the JSON-RPC 2.0 reserved range and this library's own codes (-32001 unauthorized, -32002 rate limited).

Error codes

Code Meaning
-32700 Parse error (malformed JSON)
-32600 Invalid request (missing/invalid method, id, or empty batch)
-32601 Method not found
-32602 Invalid params
-32603 Internal error (duplicate/missing handler registration)
-32000 Handler threw an unexpected exception
-32001 Unauthorized (protected method, gate denied access)
-32002 Rate limit exceeded

Documentation and license

See docs/index.md for the full guide, including a complete API reference. Published under the MIT License.

📜 License

Created with ❤️ by Aicrion. Licensed under the MIT License. Free to use, modify, and distribute!


All versions of json-rpc with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
psr/container Version ^1.0 || ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package aicrion/json-rpc contains the following files

Loading the files please wait ...