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