Expand description
Protocol-agnostic request routing for REST, GraphQL, and gRPC.
Write handlers once, expose them via any protocol:
§Example
use allframe_core::router::{Router, RestAdapter, GraphQLAdapter, GrpcAdapter};
let mut router = Router::new();
router.register("get_user", || async { r#"{"id": 1}"#.to_string() });
// Same handler, three protocols!
let mut rest = RestAdapter::new();
rest.route("GET", "/users/:id", "get_user");
let mut graphql = GraphQLAdapter::new();
graphql.query("user", "get_user");
let mut grpc = GrpcAdapter::new();
grpc.unary("UserService", "GetUser", "get_user");Also includes documentation generators:
scalar_html- Scalar UI for REST APIsgraphiql_html- GraphiQL playground for GraphQLgrpc_explorer_html- gRPC Explorer
§Protocol-Agnostic Router
Write handlers once, expose them via REST, GraphQL, and gRPC.
This is AllFrame’s core differentiator - the same handler can serve multiple protocols without code changes.
§Quick Start
use allframe_core::router::{Router, RestAdapter, GraphQLAdapter, GrpcAdapter};
// Create router and register handlers
let mut router = Router::new();
router.register("get_user", || async {
r#"{"id": 42, "name": "Alice"}"#.to_string()
});
// Expose via REST
let mut rest = RestAdapter::new();
rest.route("GET", "/users/:id", "get_user");
// Expose via GraphQL
let mut graphql = GraphQLAdapter::new();
graphql.query("user", "get_user");
// Expose via gRPC
let mut grpc = GrpcAdapter::new();
grpc.unary("UserService", "GetUser", "get_user");§Key Types
Router- Central handler registryRestAdapter- REST protocol adapterGraphQLAdapter- GraphQL protocol adapterGrpcAdapter- gRPC protocol adapterProtocolAdapter- Trait for custom protocol adapters
§API Documentation
Generate beautiful API documentation automatically:
scalar_html- Scalar UI for REST APIs (<50KB)graphiql_html- GraphiQL playground for GraphQLgrpc_explorer_html- gRPC Explorer for gRPC servicesOpenApiGenerator- OpenAPI 3.1 spec generation
§Configuration-Driven Protocol Selection
Use TOML configuration to select protocols without code changes:
[server]
protocols = ["rest", "graphql", "grpc"]
[server.rest]
port = 8080
[server.graphql]
port = 8081Re-exports§
pub use adapter::ProtocolAdapter;pub use builder::RouteBuilder;pub use config::GraphQLConfig;routerpub use config::GrpcConfig;routerpub use config::RestConfig;routerpub use config::RouterConfig;routerpub use config::ServerConfig;routerpub use contract::ContractTestConfig;pub use contract::ContractTestResult;pub use contract::ContractTestResults;pub use contract::ContractTestable;pub use contract::ContractTester;pub use docs::DocsConfig;pub use graphiql::graphiql_html;pub use graphiql::GraphiQLConfig;pub use graphiql::GraphiQLTheme;pub use graphql::GraphQLAdapter;pub use graphql::GraphQLOperation;pub use graphql::OperationType;pub use graphql_prod::GraphQLProductionAdapter;router-graphqlpub use grpc::GrpcAdapter;pub use grpc::GrpcMethod;pub use grpc::GrpcMethodType;pub use grpc::GrpcRequest;pub use grpc::GrpcStatus;pub use grpc_explorer::grpc_explorer_html;pub use grpc_explorer::GrpcExplorerConfig;pub use grpc_explorer::GrpcExplorerTheme;pub use grpc_prod::protobuf;router-grpcpub use grpc_prod::status;router-grpcpub use grpc_prod::streaming;router-grpcpub use grpc_prod::GrpcProductionAdapter;router-grpcpub use grpc_prod::GrpcService;router-grpcpub use handler::Handler;pub use handler::HandlerFn;pub use handler::HandlerWithArgs;pub use handler::HandlerWithState;pub use handler::HandlerWithStateOnly;pub use handler::IntoHandlerResult;pub use handler::IntoStreamItem;pub use handler::Json;pub use handler::State;pub use handler::StreamError;pub use handler::StreamHandler;pub use handler::StreamReceiver;pub use handler::StreamSender;pub use handler::StreamingHandlerFn;pub use handler::StreamingHandlerWithArgs;pub use handler::StreamingHandlerWithState;pub use handler::StreamingHandlerWithStateOnly;pub use handler::DEFAULT_STREAM_CAPACITY;pub use metadata::RouteMetadata;pub use method::Method;pub use openapi::OpenApiGenerator;pub use openapi::OpenApiServer;pub use rest::RestAdapter;pub use rest::RestRequest;pub use rest::RestResponse;pub use rest::RestRoute;pub use scalar::scalar_html;pub use scalar::ScalarConfig;pub use scalar::ScalarLayout;pub use scalar::ScalarTheme;pub use schema::ToJsonSchema;pub use ts_codegen::generate_ts_client;pub use ts_codegen::HandlerMeta;pub use ts_codegen::TsField;pub use ts_codegen::TsType;
Modules§
- adapter
- Protocol adapter trait for supporting multiple protocols
- builder
- Route builder for fluent route configuration
- config
router - Configuration-driven protocol selection
- contract
- Contract Testing Support
- docs
- Documentation serving helpers
- graphiql
- GraphiQL Playground Integration
- graphql
- GraphQL protocol adapter
- graphql_
prod router-graphql - Production GraphQL adapter using async-graphql
- grpc
- gRPC protocol adapter
- grpc_
explorer - gRPC Service Explorer Integration
- grpc_
prod router-grpc - Production gRPC adapter using tonic and prost
- handler
- Handler trait and implementations for protocol-agnostic request handling
- metadata
- Route metadata for documentation generation
- method
- HTTP method types for type-safe routing
- openapi
- OpenAPI 3.1 specification generation
- rest
- REST/HTTP protocol adapter
- scalar
- Scalar UI integration for interactive OpenAPI documentation.
- schema
- JSON Schema generation for OpenAPI documentation
- ts_
codegen - TypeScript client code generation from Router handler metadata
Structs§
- Router
- Router manages handler registration and protocol adapters