1mod body;
2pub mod cookie;
3mod extract;
4mod form_request;
5mod request;
6pub mod resources;
8mod response;
9
10pub use body::{collect_body, parse_form, parse_json};
11pub use cookie::{parse_cookies, Cookie, CookieOptions, SameSite};
12pub use extract::{FromParam, FromRequest};
13pub use form_request::FormRequest;
14pub use request::{Request, RequestParts};
15pub use resources::{PaginationLinks, PaginationMeta, Resource, ResourceCollection, ResourceMap};
16pub use response::{
17 HttpResponse, InertiaRedirect, Redirect, RedirectRouteBuilder, Response, ResponseExt,
18};
19
20#[derive(Debug)]
25pub struct ParamError {
26 pub param_name: String,
28}
29
30impl From<ParamError> for HttpResponse {
31 fn from(err: ParamError) -> HttpResponse {
32 HttpResponse::json(serde_json::json!({
33 "error": format!("Missing required parameter: {}", err.param_name)
34 }))
35 .status(400)
36 }
37}
38
39impl From<ParamError> for crate::error::FrameworkError {
40 fn from(err: ParamError) -> crate::error::FrameworkError {
41 crate::error::FrameworkError::ParamError {
42 param_name: err.param_name,
43 }
44 }
45}
46
47impl From<ParamError> for Response {
48 fn from(err: ParamError) -> Response {
49 Err(HttpResponse::from(crate::error::FrameworkError::from(err)))
50 }
51}
52
53pub fn text(body: impl Into<String>) -> Response {
55 Ok(HttpResponse::text(body))
56}
57
58pub fn json(body: serde_json::Value) -> Response {
60 Ok(HttpResponse::json(body))
61}
62
63pub fn bytes(body: impl Into<bytes::Bytes>) -> Response {
67 Ok(HttpResponse::bytes(body))
68}