Crates.io | ajj |
lib.rs | ajj |
version | |
source | src |
created_at | 2025-01-22 17:22:29.442312 |
updated_at | 2025-01-31 15:50:10.084733 |
description | Simple, modern, ergonomic JSON-RPC 2.0 router built with tower and axum |
homepage | https://github.com/init4tech/rpc |
repository | https://github.com/init4tech/rpc |
max_upload_size | |
id | 1526892 |
Cargo.toml error: | TOML parse error at line 22, column 1 | 22 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A general-purpose, batteries-included JSON-RPC 2.0 router, inspired by axum's routing system.
ajj aims to provide simple, flexible, and ergonomic routing for JSON-RPC.
See the crate documentation on docs.rs for more detailed examples.
use ajj::{Router};
// Provide methods called "double" and "add" to the router.
let router = Router::<u64>::new()
// "double" returns the double of the request's parameter.
.route("double", |params: u64| async move {
Ok::<_, ()>(params * 2)
})
// "add" returns the sum of the request's parameters and the router's stored
// state.
.route("add", |params: u64, state: u64| async move {
Ok::<_, ()>(params + state)
})
// The router is provided with state, and is now ready to handle requests.
.with_state::<()>(3u64);
axum
- implements the tower::Service
trait for Router
, allowing it to
be used as an axum handler.pubsub
- adds traits and tasks for serving the router over streaming
interfaces.ws
- adds implementations of the pubsub
traits for
tokio-tungstenite.ipc
- adds implementations of the pubsub
traits for
interprocess local_sockets
.We recommend axum for serving the router over HTTP. The Router
provides an
into_axum(path: &str)
method to instantiate a new axum::Router
, and
register the router to handle requests.
For WS and IPC connections, the pubsub
module provides implementations of the
Connect
trait for [std::net::SocketAddr
] to create simple WS servers, and
interprocess::local_socket::ListenerOptions
to create simple IPC servers.
Users with more complex needs should provide their own Connect
implementations.
See the crate documentation on docs.rs for more detailed examples.
Some code in this project has been reproduced or adapted from other projects. Files containing that code contain a note at the bottom of the file indicating the original source, and containing relevant license information. Code has been reproduced from the following projects, and we are grateful for their work: