Skip to main content

sz_rust_http_facade/
lib.rs

1//! SZ-Rust HTTP Facade
2//!
3//! 提取自 `sz-rust-core` 的 HTTP 基础模块,提供响应、错误、请求三大基础能力。
4//!
5//! ## 模块结构
6//!
7//! | 模块 | 对齐 PHP | 说明 |
8//! |------|---------|------|
9//! | [`response`] | `SzController::renderJson/renderSuccess/renderError` | 标准 API 响应结构 + 便捷函数 |
10//! | [`error`] | `app\common\exception\BaseException` | 错误码枚举 + 异常类型 |
11//! | [`request`] | `$this->request->post/get/param` | 请求体/查询参数解析 |
12//!
13//! ## 用法
14//!
15//! ```ignore
16//! use sz_rust_http_facade::response::{ApiResponse, respond_html};
17//! use sz_rust_http_facade::error::{BaseException, ErrorCode};
18//! use sz_rust_http_facade::request::fetch_post_data;
19//! ```
20//!
21//! ## 与 sz-rust-core 的关系
22//!
23//! `sz-rust-core` 通过 `pub use sz_rust_http_facade as http;` 重导出本 crate,
24//! 因此 `sz_rust_core::http::response` 等价于 `sz_rust_http_facade::response`。
25//! 下游业务包推荐直接依赖 `sz-rust-http-facade` 以减少编译耦合。
26
27#![deny(unsafe_code)]
28#![warn(missing_docs)]
29
30pub mod error;
31/// GraphQL 支持(需启用 `graphql` feature)
32///
33/// 提供 [`graphql_router_dynamic`] / [`graphql::graphql_router`] 构建 GraphQL axum 路由,
34/// 以及 [`graphql::graphiql_route`] 提供 GraphiQL IDE。
35#[cfg(feature = "graphql")]
36pub mod graphql;
37#[cfg(feature = "grpc")]
38pub mod grpc;
39pub mod openapi;
40pub mod request;
41pub mod response;
42pub mod sse;
43pub mod tls;
44
45// ============================================================================
46// 便捷重导出 — 顶层直接访问常用项
47// ============================================================================
48
49pub use error::{BaseException, ErrorCode};
50pub use response::{
51    auto_respond, is_json_request, render_error, render_error_with_code, render_json,
52    render_success, respond, respond_html, respond_jsonp, respond_text, ApiResponse, JsonResponse,
53    JsonpResponse,
54};