Skip to main content

typeway_server/
lib.rs

1//! `typeway-server` — Tower/Hyper server integration for the Typeway web framework.
2//!
3//! This crate provides the HTTP server layer: handler dispatch, request
4//! extraction, response encoding, and the type-safe server builder.
5
6pub mod auth;
7#[cfg(feature = "axum-interop")]
8pub mod axum_interop;
9pub mod body;
10pub mod effects;
11pub mod error;
12pub mod extract;
13#[cfg(feature = "grpc")]
14pub mod grpc;
15#[cfg(feature = "protobuf")]
16pub mod grpc_direct;
17#[cfg(feature = "grpc")]
18pub mod grpc_dispatch;
19#[cfg(feature = "grpc")]
20pub mod grpc_stream;
21pub mod handler;
22pub mod handler_for;
23pub mod mount;
24#[cfg(feature = "multipart")]
25pub mod multipart;
26pub mod negotiate;
27#[cfg(feature = "openapi")]
28pub mod openapi;
29pub mod production;
30#[cfg(feature = "protobuf")]
31pub mod proto_extract;
32pub mod request_id;
33pub mod response;
34pub mod router;
35pub mod secure_headers;
36pub mod server;
37pub mod serves;
38pub mod sse;
39#[cfg(feature = "tls")]
40pub mod tls;
41pub mod typed;
42pub mod typed_bind;
43pub mod typed_response;
44#[cfg(feature = "ws")]
45pub mod typed_ws;
46#[cfg(feature = "ws")]
47pub mod ws;
48
49pub use body::{body_from_stream, empty_body, sse_body, BoxBody};
50pub use effects::{EffectfulLayeredServer, EffectfulServer};
51pub use error::JsonError;
52pub use extract::{
53    Cookie, CookieJar, Extension, FromRequest, FromRequestParts, Header, NamedCookie, NamedHeader,
54    Path, PathPrefixOffset, Query, State,
55};
56pub use handler::{into_boxed_handler, BoxedHandler, Handler, ResponseFuture};
57pub use handler_for::{bind, BindableEndpoint, BoundHandler};
58pub use mount::ServerBuilder;
59pub use negotiate::{
60    AcceptHeader, CsvFormat, HtmlFormat, JsonFormat, NegotiateFormats, NegotiatedResponse,
61    RenderAs, RenderAsXml, TextFormat, XmlFormat,
62};
63pub use response::{IntoResponse, Json};
64pub use router::{Router, RouterService};
65pub use secure_headers::SecureHeadersLayer;
66pub use server::{serve, LayeredServer, Server};
67pub use serves::{Serves, SubApi};
68pub use sse::{keep_alive, SseEvent, SseResponse};
69
70#[cfg(feature = "grpc")]
71pub use grpc::{GrpcServer, LayeredGrpcServer};
72#[cfg(feature = "protobuf")]
73pub use grpc_direct::into_direct_handler;
74#[cfg(feature = "grpc")]
75pub use grpc_stream::{GrpcStream, GrpcStreamSender};
76#[cfg(feature = "protobuf")]
77pub use proto_extract::Proto;
78
79/// Re-export tower-http for middleware layers.
80pub use tower_http;
81
82/// Re-export tracing for structured logging.
83pub use tracing;
84
85/// Collect handler doc constants into a slice for [`Server::with_openapi_docs`].
86///
87/// Pass the `SCREAMING_SNAKE_CASE_DOC` constants generated by
88/// `#[documented_handler]`.
89///
90/// # Example
91///
92/// ```ignore
93/// use typeway_macros::documented_handler;
94/// use typeway_server::handler_docs;
95///
96/// /// List users.
97/// #[documented_handler(tags = "users")]
98/// async fn list_users() -> Json<Vec<User>> { /* ... */ }
99///
100/// /// Get one user.
101/// #[documented_handler(tags = "users")]
102/// async fn get_user(id: Path<u32>) -> Json<User> { /* ... */ }
103///
104/// Server::<API>::new(handlers)
105///     .with_openapi_docs("My API", "1.0", &handler_docs![
106///         LIST_USERS_DOC,
107///         GET_USER_DOC,
108///     ])
109///     .serve(addr)
110///     .await?;
111/// ```
112#[macro_export]
113macro_rules! handler_docs {
114    ($($doc:expr),* $(,)?) => {
115        [$($doc),*]
116    };
117}