spikard_http/jsonrpc/
mod.rs1pub mod http_handler;
7pub mod method_registry;
8pub mod openrpc;
9pub mod protocol;
10pub mod router;
11
12use serde::{Deserialize, Serialize};
13
14pub use http_handler::{JsonRpcState, handle_jsonrpc};
15pub use method_registry::{JsonRpcMethodRegistry, MethodExample, MethodMetadata};
16pub use openrpc::generate_openrpc_spec;
17pub use protocol::{
18 JsonRpcErrorResponse, JsonRpcRequest, JsonRpcResponse, JsonRpcResponseType, error_codes, validate_method_name,
19};
20pub use router::{JsonRpcRequestOrBatch, JsonRpcRouter};
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct JsonRpcConfig {
25 #[serde(default)]
27 pub enabled: bool,
28 #[serde(default = "default_endpoint_path")]
30 pub endpoint_path: String,
31 #[serde(default = "default_true")]
33 pub enable_batch: bool,
34 #[serde(default = "default_max_batch_size")]
36 pub max_batch_size: usize,
37}
38
39fn default_endpoint_path() -> String {
40 "/rpc".to_string()
41}
42
43fn default_true() -> bool {
44 true
45}
46
47fn default_max_batch_size() -> usize {
48 100
49}
50
51impl Default for JsonRpcConfig {
52 fn default() -> Self {
53 Self {
54 enabled: true,
55 endpoint_path: default_endpoint_path(),
56 enable_batch: default_true(),
57 max_batch_size: default_max_batch_size(),
58 }
59 }
60}