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
//! Web server handling API
//!
//! This module contains facilities needed to process HTTP requests.
//!
//! # Register Web Handler
//!
//! To register web handler it's usually enoght to use the attribute:
//!
//! ```rust,no_run
//! use edgedb_sdk::web;
//! #[web::handler]
//! fn web_handler(req: web::Request) -> web::Response {
//! web::response()
//! .status(web::StatusCode::OK)
//! .header("Content-Type", "text/html")
//! .body("Hello <b>World</b>".into())
//! .expect("response is built")
//! }
//! ```
//!
//! # Programmatically Register Web Handler
//!
//! It's sometimes useful to do that programmatically. This is usually done in
//! [`init_hook`](macro@crate::init_hook) and [`register_handler()`]:
//!
//! ```rust,no_run
//! use edgedb_sdk::{init_hook, web};
//!
//! #[init_hook]
//! fn init() {
//! web::register_handler(web_handler);
//! }
//!
//! fn web_handler(req: web::Request) -> web::Response {
//! todo!();
//! }
//! ```
use OnceCell;
pub use web_handler as handler;
pub use StatusCode;
/// Re-exported type from [`http`](http::Response) crate
pub type Response = Response;
/// Web Request
///
/// Currently it dereferences to [`http::Request`] so see its documentation
/// for more info.
type WebHandler = fn ;
pub static WEB_HANDLER: = new;
/// Register a function as a web handler
///
/// # Panics
///
/// Panics if called more than once (including implicitly by [`handler`]
/// macro).
/// Create a response builder
///
/// See [`http`](`http::response::Builder`) crate documentation for more info.