kit_rs/
lib.rs

1pub mod http;
2pub mod inertia;
3pub mod routing;
4pub mod server;
5
6pub use http::{json, text, HttpResponse, Request, Response, ResponseExt};
7pub use inertia::{InertiaConfig, InertiaContext, InertiaResponse};
8pub use routing::Router;
9pub use server::Server;
10
11// Re-export for macro usage
12#[doc(hidden)]
13pub use serde_json;
14
15#[macro_export]
16macro_rules! json_response {
17    ($($json:tt)+) => {
18        Ok($crate::HttpResponse::json($crate::serde_json::json!($($json)+)))
19    };
20}
21
22#[macro_export]
23macro_rules! text_response {
24    ($text:expr) => {
25        Ok($crate::HttpResponse::text($text))
26    };
27}
28
29/// Create an Inertia response - automatically detects request type from context
30///
31/// # Examples
32/// ```rust
33/// inertia_response!("Dashboard", { "user": { "name": "John" } })
34/// ```
35#[macro_export]
36macro_rules! inertia_response {
37    ($component:expr, $props:tt) => {{
38        let props = $crate::serde_json::json!($props);
39        let url = $crate::InertiaContext::current_path();
40        let response = $crate::InertiaResponse::new($component, props, url);
41
42        if $crate::InertiaContext::is_inertia_request() {
43            Ok(response.to_json_response())
44        } else {
45            Ok(response.to_html_response())
46        }
47    }};
48
49    ($component:expr, $props:tt, $config:expr) => {{
50        let props = $crate::serde_json::json!($props);
51        let url = $crate::InertiaContext::current_path();
52        let response = $crate::InertiaResponse::new($component, props, url)
53            .with_config($config);
54
55        if $crate::InertiaContext::is_inertia_request() {
56            Ok(response.to_json_response())
57        } else {
58            Ok(response.to_html_response())
59        }
60    }};
61}