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 = 8081Modules§
- adapter
- Protocol adapter trait for supporting multiple protocols
- builder
- Route builder for fluent route configuration
- config
- Configuration-driven protocol selection
- contract
- Contract Testing Support
- docs
- Documentation serving helpers
- graphiql
- GraphiQL Playground Integration
- graphql
- GraphQL protocol adapter
- grpc
- gRPC protocol adapter
- grpc_
explorer - gRPC Service Explorer Integration
- 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
Structs§
- Contract
Test Config - Contract testing configuration
- Contract
Test Result - Contract test result for a single route
- Contract
Test Results - Collection of contract test results
- Contract
Tester - Contract tester for API routes
- Docs
Config - Documentation configuration
- GraphQL
Adapter - GraphQL adapter for GraphQL queries and mutations
- GraphQL
Config - GraphQL protocol configuration
- GraphQL
Operation - GraphQL operation definition
- GraphiQL
Config - GraphiQL playground configuration
- Grpc
Adapter - gRPC adapter for gRPC services and RPCs
- Grpc
Config - gRPC protocol configuration
- Grpc
Explorer Config - gRPC Explorer configuration
- Grpc
Method - gRPC service method definition
- Grpc
Request - gRPC request structure
- Handler
Fn - Wrapper for function-based handlers with no arguments
- Open
ApiGenerator - OpenAPI specification generator
- Open
ApiServer - OpenAPI server configuration
- Rest
Adapter - REST adapter for HTTP requests
- Rest
Config - REST protocol configuration
- Rest
Request - Simplified HTTP request representation
- Rest
Response - Simplified HTTP response representation
- Rest
Route - REST route definition
- Route
Builder - Builder for configuring a route with metadata
- Route
Metadata - Metadata about a registered route
- Router
- Router manages handler registration and protocol adapters
- Router
Config - Router configuration with protocol selection
- Scalar
Config - Configuration for Scalar UI
- Server
Config - Server configuration
Enums§
- GraphiQL
Theme - GraphiQL theme options
- Grpc
Explorer Theme - gRPC Explorer theme options
- Grpc
Method Type - gRPC method type (streaming mode)
- Grpc
Status - gRPC status codes
- Method
- HTTP method for REST routes
- Operation
Type - GraphQL operation type
- Scalar
Layout - Scalar UI layout options
- Scalar
Theme - Scalar UI theme options
Traits§
- Contract
Testable - Helper trait for generating contract tests
- Handler
- Handler trait for protocol-agnostic request handling
- Protocol
Adapter - Protocol adapter trait
- ToJson
Schema - Trait for types that can be converted to JSON Schema
Functions§
- graphiql_
html - Generate GraphiQL playground HTML
- grpc_
explorer_ html - Generate gRPC Explorer HTML
- scalar_
html - Generate Scalar HTML page