1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//! # `reflectapi` - is a library and a toolkit for writing web API services in Rust and generating compatible clients,
//! delivering great development experience and efficiency.
//!
//! ## Quick start
//!
//! Server application side example:
//! (complete main.rs example can be found in [https://github.com/thepartly/reflectapi/tree/main/reflectapi-demo](https://github.com/thepartly/reflectapi/tree/main/reflectapi-demo))
//!
//! ```rust
//!
//! #[derive(Debug)]
//! pub struct AppState {
//! pub books: Vec<Book>,
//! }
//!
//! async fn books_list(
//! state: std::sync::Arc<AppState>,
//! input: proto::Cursor,
//! headers: proto::Authorization,
//! ) -> Result<proto::Items<Book>, proto::BooksListError> {
//! unimplemented!("just a demo of API signature")
//! }
//!
//! pub fn builder() -> reflectapi::Builder<std::sync::Arc<AppState>> {
//! reflectapi::Builder::new()
//! .route(books_list, |b| {
//! b.name("books.list").description("List all books")
//! })
//! }
//!
//! impl Default for AppState {
//! fn default() -> Self {
//! Self {
//! books: vec![Book {
//! isbn: "978-3-16-148410-0".into(),
//! title: "The Catcher in the Rye".into(),
//! }],
//! }
//! }
//! }
//!
//! #[derive(
//! Debug, Clone, serde::Serialize, serde::Deserialize, reflectapi::Input, reflectapi::Output,
//! )]
//! pub struct Book {
//! /// ISBN - identity
//! pub isbn: String,
//! /// Title
//! pub title: String,
//! }
//!
//! pub mod proto {
//! #[derive(serde::Deserialize, reflectapi::Input)]
//! pub struct Authorization {
//! pub authorization: String,
//! }
//!
//! #[derive(serde::Deserialize, reflectapi::Input)]
//! pub struct Cursor {
//! #[serde(default)]
//! pub cursor: Option<String>,
//! #[serde(default)]
//! pub limit: Option<u32>,
//! }
//! #[derive(serde::Serialize, reflectapi::Output)]
//! pub struct Items<T> {
//! pub items: Vec<T>,
//! pub pagination: Pagination,
//! }
//!
//! #[derive(serde::Serialize, reflectapi::Output)]
//! pub struct Pagination {
//! pub next_cursor: Option<String>,
//! pub prev_cursor: Option<String>,
//! }
//!
//! #[derive(serde::Serialize, reflectapi::Output)]
//! pub enum BooksListError {
//! Unauthorized,
//! LimitExceeded { requested: u32, allowed: u32 },
//! }
//!
//! impl reflectapi::StatusCode for BooksListError {
//! fn status_code(&self) -> http::StatusCode {
//! match self {
//! BooksListError::Unauthorized => http::StatusCode::UNAUTHORIZED,
//! BooksListError::LimitExceeded { .. } => http::StatusCode::UNPROCESSABLE_ENTITY,
//! }
//! }
//! }
//! }
//! ```
//!
//! Generated client in Typescript (one of the languages supported by the codegen) example:
//!
//! ```typescript
//! import { client, match } from './generated';
//
//! async function main() {
//! const c = client('http://localhost:3000');
//
//! const result = await c.books.list({}, {
//! authorization: 'password'
//! })
//! let { items, pagination } = result.unwrap_ok_or_else((e) => {
//! throw match(e.unwrap(), {
//! Unauthorized: () => 'NotAuthorized',
//! LimitExceeded: ({ requested, allowed }) => `Limit exceeded: ${requested} > ${allowed}`,
//! });
//! });
//! console.log(`items: ${items[0]?.author}`);
//! console.log(`next cursor: ${pagination.next_cursor}`);
//! }
//
//! main()
//! .then(() => console.log('done'))
//! .catch((err) => console.error(err));
//! ```
//!
//! For complete examples, see the [`reflectapi-demo`](https://github.com/thepartly/reflectapi/tree/main/reflectapi-demo) crate which demonstrates:
//! - Basic CRUD operations
//! - Tagged enums and discriminated unions
//! - Generic types and collections
//! - Error handling
//! - Multiple serialization formats
//! - Project structure setup
//! - Online docs embedding
//! - And many more features
//!
pub
pub use ;
pub use *;
pub use *;
pub use *;
pub use ;
pub use *;
pub use *;
// Hidden re-exports
// #[doc(hidden)]
// pub use builder::*;
pub use *;