[{"data":1,"prerenderedAt":1385},["ShallowReactive",2],{"$fZA-RtrMfOIk7xZiAtUeGKBbicmA-vEbjPjEX-rp6nmU":3},{"slug":4,"title":5,"description":6,"source":7,"document":8,"toc":1365,"editUrl":1379,"prev":1380,"next":1383},"overview\u002Fcontrollers","Controllers","Handle incoming HTTP requests with","---\ntitle: Controllers\ndescription: Handle incoming HTTP requests with #[controller], #[impl_controller] and route macros.\n---\n\n# Controllers\n\nControllers are the entry point for HTTP traffic. They bind **routes** to **handlers**, declare a route prefix, and can opt into the request pipeline (guards, interceptors, middleware, and exception filters).\n\n## Define a controller\n\nDeclare a plain struct with the `#[controller(\"\u002Fprefix\")]` macro, then implement your handlers inside an `#[impl_controller]` block:\n\n```rust\nuse ferrite_framework::{controller, impl_controller, get, inject, Json, HttpError};\n\n#[controller(\"\u002Fusers\")]\npub struct UsersController;\n\n#[impl_controller]\nimpl UsersController {\n    #[get(\"\u002F\")]\n    pub async fn list(&self) -> Result\u003CJson\u003CVec\u003CUser>>, HttpError> {\n        \u002F\u002F ...\n    }\n}\n```\n\n### Rules\n\n- `#[controller]` applies to a **struct** (no generics) with at least one named field — or no fields at all, like `UsersController`.\n- Every field is automatically rewritten to `Arc\u003CT>`, so handlers hold cheap shared handles.\n- `#[impl_controller]` applies to an **inherent impl block**, and every handler must be `async fn` taking `&self`.\n- If the controllers struct has fields, provide its constructor with `#[inject]`:\n\n```rust\n#[controller(\"\u002Fusers\")]\npub struct UsersController {\n    service: UsersService,\n}\n\n#[impl_controller]\nimpl UsersController {\n    #[inject]\n    pub fn new(service: UsersService) -> Self {\n        Self { service }\n    }\n\n    #[get(\"\u002F{id}\")]\n    pub async fn show(&self, Path(id): Path\u003Ci64>) -> Result\u003CJson\u003CUser>, HttpError> {\n        \u002F\u002F ...\n    }\n}\n```\n\n### Route prefix\n\nThe prefix is taken from the first path argument. You can also pass `version`:\n\n```rust\n#[controller(\"\u002Fapi\u002Fv1\u002Fusers\")]\npub struct UsersController;\n```\n\n## Route macros\n\n| Macro | HTTP methods | Notes |\n| --- | --- | --- |\n| `#[get(\"\u002F...\")]` | GET | |\n| `#[post(\"\u002F...\")]` | POST | |\n| `#[put(\"\u002F...\")]` | PUT | |\n| `#[patch(\"\u002F...\")]` | PATCH | |\n| `#[delete(\"\u002F...\")]` | DELETE | |\n| `#[all(\"\u002F...\")]` | ANY | registered with `axum::routing::any` |\n\nRoute patterns follow [Axum path syntax](https:\u002F\u002Fdocs.rs\u002Faxum\u002Flatest\u002Faxum\u002Fextract\u002Fstruct.Path.html), so `{id}` captures a single segment:\n\n```rust\n#[impl_controller]\nimpl UsersController {\n    #[get(\"\u002F{id}\")]\n    pub async fn show(&self, Path(id): Path\u003Ci64>) -> Result\u003CJson\u003CUser>, HttpError> { \u002F* ... *\u002F }\n\n    #[post(\"\u002F\")]\n    pub async fn create(&self, Json(dto): Json\u003CCreateUserDto>) -> Result\u003CJson\u003CUser>, HttpError> { \u002F* ... *\u002F }\n\n    #[patch(\"\u002F{id}\")]\n    pub async fn update(&self, Path(id): Path\u003Ci64>, Json(dto): Json\u003CUpdateUserDto>) -> Result\u003CJson\u003CUser>, HttpError> { \u002F* ... *\u002F }\n\n    #[delete(\"\u002F{id}\")]\n    pub async fn remove(&self, Path(id): Path\u003Ci64>) -> Result\u003CJson\u003C()>, HttpError> { \u002F* ... *\u002F }\n}\n```\n\n## Handlers\n\nHandlers can return anything that implements `IntoResponse` (Axum) — strings, `Json\u003CT>`, `Result\u003CT, HttpError>`, `StatusCode`, and so on.\n\n### Extractors\n\nFerrite re-exports the Axum extractors you need:\n\n- `Path\u003CT>` — path parameters (`Path(id): Path\u003Ci64>`)\n- `Query\u003CT>` — query string (`Query(params): Query\u003CSearchDto>`)\n- `State\u003CT>` — shared application state\n- `Json\u003CT>` from `ferrite_framework::Json` — the *validating* JSON extractor (see [Validation](\u002Fdocs\u002Foverview\u002Fvalidation))\n- `Json\u003CT>` from `ferrite_framework::extract::Json` \u002F `ferrite_http::Json` — the plain Axum JSON body codec\n\n> Note: `ferrite_framework::Json` is the **validating** extractor. Plain Axum JSON lives at `ferrite_framework::extract::Json`. Services like `ferrite-health` import it as `HttpJson` to stay unambiguous.\n\n### Errors\n\nReturn `Result\u003CT, HttpError>` and use the typed constructors when you want to fail fast:\n\n```rust\nuse ferrite_framework::HttpError;\n\nreturn Err(HttpError::not_found(\"user\"));\nreturn Err(HttpError::bad_request(\"invalid payload\"));\nreturn Err(HttpError::unauthorized(\"missing token\"));\nreturn Err(HttpError::conflict(\"email already taken\"));\n```\n\nAn `HttpError` renders as `{\"statusCode\": \u003Cu16>, \"message\": \"...\"}`. To transform a *different* error type, chain it:\n\n```rust\nErr(HttpError::new(service.create(&dto).await.context(\"create user\")?))\n```\n\n## Request context\n\nFor guards, middleware, and interceptors you'll interact with `RequestCtx`, which wraps the raw HTTP request parts:\n\n```rust\nuse ferrite_framework::RequestCtx;\n\nctx.method()      \u002F\u002F &str\nctx.uri()         \u002F\u002F &Uri\nctx.headers()     \u002F\u002F &HeaderMap\nctx.header(\"Authorization\")\nctx.header_str(\"X-Trace-Id\") -> Option\u003C&str>\n```\n\n## Route metadata\n\nThe macros record per-route metadata (request body DTO types and guard types) into an inventory registry. `ferrite-swagger` reads this to generate OpenAPI request bodies and `401` security blocks automatically — see [OpenAPI & Swagger](\u002Fdocs\u002Ffundamentals\u002Fopenapi-swagger).\n\n## Next steps\n\n- [Providers](\u002Fdocs\u002Foverview\u002Fproviders) — build the services your controllers depend on.\n- [Guards](\u002Fdocs\u002Foverview\u002Fguards) — protect routes with `#[use_guards]`.\n- [Pipes](\u002Fdocs\u002Foverview\u002Fpipes) — transform and validate inputs.",{"frontmatter":9,"meta":10,"nodes":48},{"title":5,"description":6},{"toc":11},{"title":12,"searchDepth":13,"depth":14,"links":15},"On This Page",2,3,[16,26,29,39,42,45],{"id":17,"depth":13,"text":18,"children":19},"define-a-controller","Define a controller",[20,23],{"id":21,"depth":14,"text":22},"define-a-controller-rules","Rules",{"id":24,"depth":14,"text":25},"define-a-controller-route-prefix","Route prefix",{"id":27,"depth":13,"text":28},"route-macros","Route macros",{"id":30,"depth":13,"text":31,"children":32},"handlers","Handlers",[33,36],{"id":34,"depth":14,"text":35},"handlers-extractors","Extractors",{"id":37,"depth":14,"text":38},"handlers-errors","Errors",{"id":40,"depth":13,"text":41},"request-context","Request context",{"id":43,"depth":13,"text":44},"route-metadata","Route metadata",{"id":46,"depth":13,"text":47},"next-steps","Next steps",[49,53,65,68,80,247,250,298,473,475,481,504,506,605,618,916,918,935,937,940,997,1018,1020,1026,1135,1149,1200,1202,1209,1320,1322,1337,1339],[50,51,5],"h1",{"id":52},"controllers",[54,55,56,57,61,62,64],"p",{},"Controllers are the entry point for HTTP traffic. They bind ",[58,59,60],"strong",{},"routes"," to ",[58,63,30],{},", declare a route prefix, and can opt into the request pipeline (guards, interceptors, middleware, and exception filters).",[66,67,18],"h2",{"id":17},[54,69,70,71,75,76,79],{},"Declare a plain struct with the ",[72,73,74],"code",{},"#[controller(\"\u002Fprefix\")]"," macro, then implement your handlers inside an ",[72,77,78],{},"#[impl_controller]"," block:",[81,82,85],"pre",{"language":83,"class":84},"rust","shiki shiki-themes github-light github-dark dark:github-dark",[72,86,88,120,121,120,123,120,135,120,149,120,151,120,155,120,165,120,175,120,231,120,237,120,242],{"class":87},"language-rust",[89,90,93,97,101,104,108,111,114,117],"span",{"class":91,"style":92},"line","display: inline",[89,94,96],{"style":95},"color:#D73A49;--shiki-dark:#F97583","use",[89,98,100],{"style":99},"color:#6F42C1;--shiki-dark:#B392F0"," ferrite_framework",[89,102,103],{"style":95},"::",[89,105,107],{"style":106},"color:#24292E;--shiki-dark:#E1E4E8","{controller, impl_controller, get, inject, ",[89,109,110],{"style":99},"Json",[89,112,113],{"style":106},", ",[89,115,116],{"style":99},"HttpError",[89,118,119],{"style":106},"};","\n",[89,122],{"class":91,"style":92},[89,124,125,128,132],{"class":91,"style":92},[89,126,127],{"style":106},"#[controller(",[89,129,131],{"style":130},"color:#032F62;--shiki-dark:#9ECBFF","\"\u002Fusers\"",[89,133,134],{"style":106},")]",[89,136,137,140,143,146],{"class":91,"style":92},[89,138,139],{"style":95},"pub",[89,141,142],{"style":95}," struct",[89,144,145],{"style":99}," UsersController",[89,147,148],{"style":106},";",[89,150],{"class":91,"style":92},[89,152,153],{"class":91,"style":92},[89,154,78],{"style":106},[89,156,157,160,162],{"class":91,"style":92},[89,158,159],{"style":95},"impl",[89,161,145],{"style":99},[89,163,164],{"style":106}," {",[89,166,167,170,173],{"class":91,"style":92},[89,168,169],{"style":106},"    #[get(",[89,171,172],{"style":130},"\"\u002F\"",[89,174,134],{"style":106},[89,176,177,180,183,186,189,192,195,199,202,205,208,211,213,215,218,220,223,226,228],{"class":91,"style":92},[89,178,179],{"style":95},"    pub",[89,181,182],{"style":95}," async",[89,184,185],{"style":95}," fn",[89,187,188],{"style":99}," list",[89,190,191],{"style":106},"(",[89,193,194],{"style":95},"&",[89,196,198],{"style":197},"color:#005CC5;--shiki-dark:#79B8FF","self",[89,200,201],{"style":106},") ",[89,203,204],{"style":95},"->",[89,206,207],{"style":99}," Result",[89,209,210],{"style":106},"\u003C",[89,212,110],{"style":99},[89,214,210],{"style":106},[89,216,217],{"style":99},"Vec",[89,219,210],{"style":106},[89,221,222],{"style":99},"User",[89,224,225],{"style":106},">>, ",[89,227,116],{"style":99},[89,229,230],{"style":106},"> {",[89,232,233],{"class":91,"style":92},[89,234,236],{"style":235},"color:#6A737D;--shiki-dark:#6A737D","        \u002F\u002F ...",[89,238,239],{"class":91,"style":92},[89,240,241],{"style":106},"    }",[89,243,244],{"class":91,"style":92},[89,245,246],{"style":106},"}",[248,249,22],"h3",{"id":21},[251,252,253,268,275,291],"ul",{},[254,255,256,259,260,263,264,267],"li",{},[72,257,258],{},"#[controller]"," applies to a ",[58,261,262],{},"struct"," (no generics) with at least one named field — or no fields at all, like ",[72,265,266],{},"UsersController",".",[254,269,270,271,274],{},"Every field is automatically rewritten to ",[72,272,273],{},"Arc\u003CT>",", so handlers hold cheap shared handles.",[254,276,277,279,280,283,284,287,288,267],{},[72,278,78],{}," applies to an ",[58,281,282],{},"inherent impl block",", and every handler must be ",[72,285,286],{},"async fn"," taking ",[72,289,290],{},"&self",[254,292,293,294,297],{},"If the controllers struct has fields, provide its constructor with ",[72,295,296],{},"#[inject]",":",[81,299,300],{"language":83,"class":84},[72,301,302,120,310,120,320,120,333,120,337,120,339,120,343,120,351,120,356,120,381,120,389,120,393,120,395,120,404,120,461,120,465,120,469],{"class":87},[89,303,304,306,308],{"class":91,"style":92},[89,305,127],{"style":106},[89,307,131],{"style":130},[89,309,134],{"style":106},[89,311,312,314,316,318],{"class":91,"style":92},[89,313,139],{"style":95},[89,315,142],{"style":95},[89,317,145],{"style":99},[89,319,164],{"style":106},[89,321,322,325,327,330],{"class":91,"style":92},[89,323,324],{"style":106},"    service",[89,326,297],{"style":95},[89,328,329],{"style":99}," UsersService",[89,331,332],{"style":106},",",[89,334,335],{"class":91,"style":92},[89,336,246],{"style":106},[89,338],{"class":91,"style":92},[89,340,341],{"class":91,"style":92},[89,342,78],{"style":106},[89,344,345,347,349],{"class":91,"style":92},[89,346,159],{"style":95},[89,348,145],{"style":99},[89,350,164],{"style":106},[89,352,353],{"class":91,"style":92},[89,354,355],{"style":106},"    #[inject]",[89,357,358,360,362,365,368,370,372,374,376,379],{"class":91,"style":92},[89,359,179],{"style":95},[89,361,185],{"style":95},[89,363,364],{"style":99}," new",[89,366,367],{"style":106},"(service",[89,369,297],{"style":95},[89,371,329],{"style":99},[89,373,201],{"style":106},[89,375,204],{"style":95},[89,377,378],{"style":197}," Self",[89,380,164],{"style":106},[89,382,383,386],{"class":91,"style":92},[89,384,385],{"style":197},"        Self",[89,387,388],{"style":106}," { service }",[89,390,391],{"class":91,"style":92},[89,392,241],{"style":106},[89,394],{"class":91,"style":92},[89,396,397,399,402],{"class":91,"style":92},[89,398,169],{"style":106},[89,400,401],{"style":130},"\"\u002F{id}\"",[89,403,134],{"style":106},[89,405,406,408,410,412,415,417,419,421,423,426,429,431,434,436,439,442,444,446,448,450,452,454,457,459],{"class":91,"style":92},[89,407,179],{"style":95},[89,409,182],{"style":95},[89,411,185],{"style":95},[89,413,414],{"style":99}," show",[89,416,191],{"style":106},[89,418,194],{"style":95},[89,420,198],{"style":197},[89,422,113],{"style":106},[89,424,425],{"style":99},"Path",[89,427,428],{"style":106},"(id)",[89,430,297],{"style":95},[89,432,433],{"style":99}," Path",[89,435,210],{"style":106},[89,437,438],{"style":99},"i64",[89,440,441],{"style":106},">) ",[89,443,204],{"style":95},[89,445,207],{"style":99},[89,447,210],{"style":106},[89,449,110],{"style":99},[89,451,210],{"style":106},[89,453,222],{"style":99},[89,455,456],{"style":106},">, ",[89,458,116],{"style":99},[89,460,230],{"style":106},[89,462,463],{"class":91,"style":92},[89,464,236],{"style":235},[89,466,467],{"class":91,"style":92},[89,468,241],{"style":106},[89,470,471],{"class":91,"style":92},[89,472,246],{"style":106},[248,474,25],{"id":24},[54,476,477,478,297],{},"The prefix is taken from the first path argument. You can also pass ",[72,479,480],{},"version",[81,482,483],{"language":83,"class":84},[72,484,485,120,494],{"class":87},[89,486,487,489,492],{"class":91,"style":92},[89,488,127],{"style":106},[89,490,491],{"style":130},"\"\u002Fapi\u002Fv1\u002Fusers\"",[89,493,134],{"style":106},[89,495,496,498,500,502],{"class":91,"style":92},[89,497,139],{"style":95},[89,499,142],{"style":95},[89,501,145],{"style":99},[89,503,148],{"style":106},[66,505,28],{"id":27},[507,508,509,525],"table",{},[510,511,512],"thead",{},[513,514,515,519,522],"tr",{},[516,517,518],"th",{},"Macro",[516,520,521],{},"HTTP methods",[516,523,524],{},"Notes",[526,527,528,541,553,565,577,589],"tbody",{},[513,529,530,536,539],{},[531,532,533],"td",{},[72,534,535],{},"#[get(\"\u002F...\")]",[531,537,538],{},"GET",[531,540],{},[513,542,543,548,551],{},[531,544,545],{},[72,546,547],{},"#[post(\"\u002F...\")]",[531,549,550],{},"POST",[531,552],{},[513,554,555,560,563],{},[531,556,557],{},[72,558,559],{},"#[put(\"\u002F...\")]",[531,561,562],{},"PUT",[531,564],{},[513,566,567,572,575],{},[531,568,569],{},[72,570,571],{},"#[patch(\"\u002F...\")]",[531,573,574],{},"PATCH",[531,576],{},[513,578,579,584,587],{},[531,580,581],{},[72,582,583],{},"#[delete(\"\u002F...\")]",[531,585,586],{},"DELETE",[531,588],{},[513,590,591,596,599],{},[531,592,593],{},[72,594,595],{},"#[all(\"\u002F...\")]",[531,597,598],{},"ANY",[531,600,601,602],{},"registered with ",[72,603,604],{},"axum::routing::any",[54,606,607,608,613,614,617],{},"Route patterns follow ",[609,610,612],"a",{"href":611},"https:\u002F\u002Fdocs.rs\u002Faxum\u002Flatest\u002Faxum\u002Fextract\u002Fstruct.Path.html","Axum path syntax",", so ",[72,615,616],{},"{id}"," captures a single segment:",[81,619,620],{"language":83,"class":84},[72,621,622,120,626,120,634,120,642,120,699,120,701,120,710,120,768,120,770,120,779,120,849,120,851,120,860,120,912],{"class":87},[89,623,624],{"class":91,"style":92},[89,625,78],{"style":106},[89,627,628,630,632],{"class":91,"style":92},[89,629,159],{"style":95},[89,631,145],{"style":99},[89,633,164],{"style":106},[89,635,636,638,640],{"class":91,"style":92},[89,637,169],{"style":106},[89,639,401],{"style":130},[89,641,134],{"style":106},[89,643,644,646,648,650,652,654,656,658,660,662,664,666,668,670,672,674,676,678,680,682,684,686,688,690,693,696],{"class":91,"style":92},[89,645,179],{"style":95},[89,647,182],{"style":95},[89,649,185],{"style":95},[89,651,414],{"style":99},[89,653,191],{"style":106},[89,655,194],{"style":95},[89,657,198],{"style":197},[89,659,113],{"style":106},[89,661,425],{"style":99},[89,663,428],{"style":106},[89,665,297],{"style":95},[89,667,433],{"style":99},[89,669,210],{"style":106},[89,671,438],{"style":99},[89,673,441],{"style":106},[89,675,204],{"style":95},[89,677,207],{"style":99},[89,679,210],{"style":106},[89,681,110],{"style":99},[89,683,210],{"style":106},[89,685,222],{"style":99},[89,687,456],{"style":106},[89,689,116],{"style":99},[89,691,692],{"style":106},"> { ",[89,694,695],{"style":235},"\u002F* ... *\u002F",[89,697,698],{"style":106}," }",[89,700],{"class":91,"style":92},[89,702,703,706,708],{"class":91,"style":92},[89,704,705],{"style":106},"    #[post(",[89,707,172],{"style":130},[89,709,134],{"style":106},[89,711,712,714,716,718,721,723,725,727,729,731,734,736,739,741,744,746,748,750,752,754,756,758,760,762,764,766],{"class":91,"style":92},[89,713,179],{"style":95},[89,715,182],{"style":95},[89,717,185],{"style":95},[89,719,720],{"style":99}," create",[89,722,191],{"style":106},[89,724,194],{"style":95},[89,726,198],{"style":197},[89,728,113],{"style":106},[89,730,110],{"style":99},[89,732,733],{"style":106},"(dto)",[89,735,297],{"style":95},[89,737,738],{"style":99}," Json",[89,740,210],{"style":106},[89,742,743],{"style":99},"CreateUserDto",[89,745,441],{"style":106},[89,747,204],{"style":95},[89,749,207],{"style":99},[89,751,210],{"style":106},[89,753,110],{"style":99},[89,755,210],{"style":106},[89,757,222],{"style":99},[89,759,456],{"style":106},[89,761,116],{"style":99},[89,763,692],{"style":106},[89,765,695],{"style":235},[89,767,698],{"style":106},[89,769],{"class":91,"style":92},[89,771,772,775,777],{"class":91,"style":92},[89,773,774],{"style":106},"    #[patch(",[89,776,401],{"style":130},[89,778,134],{"style":106},[89,780,781,783,785,787,790,792,794,796,798,800,802,804,806,808,810,812,814,816,818,820,822,825,827,829,831,833,835,837,839,841,843,845,847],{"class":91,"style":92},[89,782,179],{"style":95},[89,784,182],{"style":95},[89,786,185],{"style":95},[89,788,789],{"style":99}," update",[89,791,191],{"style":106},[89,793,194],{"style":95},[89,795,198],{"style":197},[89,797,113],{"style":106},[89,799,425],{"style":99},[89,801,428],{"style":106},[89,803,297],{"style":95},[89,805,433],{"style":99},[89,807,210],{"style":106},[89,809,438],{"style":99},[89,811,456],{"style":106},[89,813,110],{"style":99},[89,815,733],{"style":106},[89,817,297],{"style":95},[89,819,738],{"style":99},[89,821,210],{"style":106},[89,823,824],{"style":99},"UpdateUserDto",[89,826,441],{"style":106},[89,828,204],{"style":95},[89,830,207],{"style":99},[89,832,210],{"style":106},[89,834,110],{"style":99},[89,836,210],{"style":106},[89,838,222],{"style":99},[89,840,456],{"style":106},[89,842,116],{"style":99},[89,844,692],{"style":106},[89,846,695],{"style":235},[89,848,698],{"style":106},[89,850],{"class":91,"style":92},[89,852,853,856,858],{"class":91,"style":92},[89,854,855],{"style":106},"    #[delete(",[89,857,401],{"style":130},[89,859,134],{"style":106},[89,861,862,864,866,868,871,873,875,877,879,881,883,885,887,889,891,893,895,897,899,901,904,906,908,910],{"class":91,"style":92},[89,863,179],{"style":95},[89,865,182],{"style":95},[89,867,185],{"style":95},[89,869,870],{"style":99}," remove",[89,872,191],{"style":106},[89,874,194],{"style":95},[89,876,198],{"style":197},[89,878,113],{"style":106},[89,880,425],{"style":99},[89,882,428],{"style":106},[89,884,297],{"style":95},[89,886,433],{"style":99},[89,888,210],{"style":106},[89,890,438],{"style":99},[89,892,441],{"style":106},[89,894,204],{"style":95},[89,896,207],{"style":99},[89,898,210],{"style":106},[89,900,110],{"style":99},[89,902,903],{"style":106},"\u003C()>, ",[89,905,116],{"style":99},[89,907,692],{"style":106},[89,909,695],{"style":235},[89,911,698],{"style":106},[89,913,914],{"class":91,"style":92},[89,915,246],{"style":106},[66,917,31],{"id":30},[54,919,920,921,924,925,113,928,113,931,934],{},"Handlers can return anything that implements ",[72,922,923],{},"IntoResponse"," (Axum) — strings, ",[72,926,927],{},"Json\u003CT>",[72,929,930],{},"Result\u003CT, HttpError>",[72,932,933],{},"StatusCode",", and so on.",[248,936,35],{"id":34},[54,938,939],{},"Ferrite re-exports the Axum extractors you need:",[251,941,942,952,961,967,985],{},[254,943,944,947,948,951],{},[72,945,946],{},"Path\u003CT>"," — path parameters (",[72,949,950],{},"Path(id): Path\u003Ci64>",")",[254,953,954,957,958,951],{},[72,955,956],{},"Query\u003CT>"," — query string (",[72,959,960],{},"Query(params): Query\u003CSearchDto>",[254,962,963,966],{},[72,964,965],{},"State\u003CT>"," — shared application state",[254,968,969,971,972,975,976,980,981,951],{},[72,970,927],{}," from ",[72,973,974],{},"ferrite_framework::Json"," — the ",[977,978,979],"em",{},"validating"," JSON extractor (see ",[609,982,984],{"href":983},"\u002Fdocs\u002Foverview\u002Fvalidation","Validation",[254,986,987,971,989,992,993,996],{},[72,988,927],{},[72,990,991],{},"ferrite_framework::extract::Json"," \u002F ",[72,994,995],{},"ferrite_http::Json"," — the plain Axum JSON body codec",[998,999,1000,1001,1003,1004,1006,1007,1009,1010,1013,1014,1017],"blockquote",{},"Note: ",[72,1002,974],{}," is the ",[58,1005,979],{}," extractor. Plain Axum JSON lives at ",[72,1008,991],{},". Services like ",[72,1011,1012],{},"ferrite-health"," import it as ",[72,1015,1016],{},"HttpJson"," to stay unambiguous.",[248,1019,38],{"id":37},[54,1021,1022,1023,1025],{},"Return ",[72,1024,930],{}," and use the typed constructors when you want to fail fast:",[81,1027,1028],{"language":83,"class":84},[72,1029,1030,120,1042,120,1044,120,1069,120,1091,120,1113],{"class":87},[89,1031,1032,1034,1036,1038,1040],{"class":91,"style":92},[89,1033,96],{"style":95},[89,1035,100],{"style":99},[89,1037,103],{"style":95},[89,1039,116],{"style":99},[89,1041,148],{"style":106},[89,1043],{"class":91,"style":92},[89,1045,1046,1049,1052,1054,1056,1058,1061,1063,1066],{"class":91,"style":92},[89,1047,1048],{"style":95},"return",[89,1050,1051],{"style":99}," Err",[89,1053,191],{"style":106},[89,1055,116],{"style":99},[89,1057,103],{"style":95},[89,1059,1060],{"style":99},"not_found",[89,1062,191],{"style":106},[89,1064,1065],{"style":130},"\"user\"",[89,1067,1068],{"style":106},"));",[89,1070,1071,1073,1075,1077,1079,1081,1084,1086,1089],{"class":91,"style":92},[89,1072,1048],{"style":95},[89,1074,1051],{"style":99},[89,1076,191],{"style":106},[89,1078,116],{"style":99},[89,1080,103],{"style":95},[89,1082,1083],{"style":99},"bad_request",[89,1085,191],{"style":106},[89,1087,1088],{"style":130},"\"invalid payload\"",[89,1090,1068],{"style":106},[89,1092,1093,1095,1097,1099,1101,1103,1106,1108,1111],{"class":91,"style":92},[89,1094,1048],{"style":95},[89,1096,1051],{"style":99},[89,1098,191],{"style":106},[89,1100,116],{"style":99},[89,1102,103],{"style":95},[89,1104,1105],{"style":99},"unauthorized",[89,1107,191],{"style":106},[89,1109,1110],{"style":130},"\"missing token\"",[89,1112,1068],{"style":106},[89,1114,1115,1117,1119,1121,1123,1125,1128,1130,1133],{"class":91,"style":92},[89,1116,1048],{"style":95},[89,1118,1051],{"style":99},[89,1120,191],{"style":106},[89,1122,116],{"style":99},[89,1124,103],{"style":95},[89,1126,1127],{"style":99},"conflict",[89,1129,191],{"style":106},[89,1131,1132],{"style":130},"\"email already taken\"",[89,1134,1068],{"style":106},[54,1136,1137,1138,1140,1141,1144,1145,1148],{},"An ",[72,1139,116],{}," renders as ",[72,1142,1143],{},"{\"statusCode\": \u003Cu16>, \"message\": \"...\"}",". To transform a ",[977,1146,1147],{},"different"," error type, chain it:",[81,1150,1151],{"language":83,"class":84},[72,1152,1153],{"class":87},[89,1154,1155,1158,1160,1162,1164,1167,1169,1171,1174,1176,1178,1181,1184,1187,1189,1192,1194,1197],{"class":91,"style":92},[89,1156,1157],{"style":99},"Err",[89,1159,191],{"style":106},[89,1161,116],{"style":99},[89,1163,103],{"style":95},[89,1165,1166],{"style":99},"new",[89,1168,367],{"style":106},[89,1170,267],{"style":95},[89,1172,1173],{"style":99},"create",[89,1175,191],{"style":106},[89,1177,194],{"style":95},[89,1179,1180],{"style":106},"dto)",[89,1182,1183],{"style":95},".await.",[89,1185,1186],{"style":99},"context",[89,1188,191],{"style":106},[89,1190,1191],{"style":130},"\"create user\"",[89,1193,951],{"style":106},[89,1195,1196],{"style":95},"?",[89,1198,1199],{"style":106},"))",[66,1201,41],{"id":40},[54,1203,1204,1205,1208],{},"For guards, middleware, and interceptors you'll interact with ",[72,1206,1207],{},"RequestCtx",", which wraps the raw HTTP request parts:",[81,1210,1211],{"language":83,"class":84},[72,1212,1213,120,1225,120,1227,120,1243,120,1258,120,1273,120,1289],{"class":87},[89,1214,1215,1217,1219,1221,1223],{"class":91,"style":92},[89,1216,96],{"style":95},[89,1218,100],{"style":99},[89,1220,103],{"style":95},[89,1222,1207],{"style":99},[89,1224,148],{"style":106},[89,1226],{"class":91,"style":92},[89,1228,1229,1232,1234,1237,1240],{"class":91,"style":92},[89,1230,1231],{"style":106},"ctx",[89,1233,267],{"style":95},[89,1235,1236],{"style":99},"method",[89,1238,1239],{"style":106},"()      ",[89,1241,1242],{"style":235},"\u002F\u002F &str",[89,1244,1245,1247,1249,1252,1255],{"class":91,"style":92},[89,1246,1231],{"style":106},[89,1248,267],{"style":95},[89,1250,1251],{"style":99},"uri",[89,1253,1254],{"style":106},"()         ",[89,1256,1257],{"style":235},"\u002F\u002F &Uri",[89,1259,1260,1262,1264,1267,1270],{"class":91,"style":92},[89,1261,1231],{"style":106},[89,1263,267],{"style":95},[89,1265,1266],{"style":99},"headers",[89,1268,1269],{"style":106},"()     ",[89,1271,1272],{"style":235},"\u002F\u002F &HeaderMap",[89,1274,1275,1277,1279,1282,1284,1287],{"class":91,"style":92},[89,1276,1231],{"style":106},[89,1278,267],{"style":95},[89,1280,1281],{"style":99},"header",[89,1283,191],{"style":106},[89,1285,1286],{"style":130},"\"Authorization\"",[89,1288,951],{"style":106},[89,1290,1291,1293,1295,1298,1300,1303,1305,1307,1310,1312,1314,1317],{"class":91,"style":92},[89,1292,1231],{"style":106},[89,1294,267],{"style":95},[89,1296,1297],{"style":99},"header_str",[89,1299,191],{"style":106},[89,1301,1302],{"style":130},"\"X-Trace-Id\"",[89,1304,201],{"style":106},[89,1306,204],{"style":95},[89,1308,1309],{"style":99}," Option",[89,1311,210],{"style":106},[89,1313,194],{"style":95},[89,1315,1316],{"style":99},"str",[89,1318,1319],{"style":106},">",[66,1321,44],{"id":43},[54,1323,1324,1325,1328,1329,1332,1333,267],{},"The macros record per-route metadata (request body DTO types and guard types) into an inventory registry. ",[72,1326,1327],{},"ferrite-swagger"," reads this to generate OpenAPI request bodies and ",[72,1330,1331],{},"401"," security blocks automatically — see ",[609,1334,1336],{"href":1335},"\u002Fdocs\u002Ffundamentals\u002Fopenapi-swagger","OpenAPI & Swagger",[66,1338,47],{"id":46},[251,1340,1341,1348,1358],{},[254,1342,1343,1347],{},[609,1344,1346],{"href":1345},"\u002Fdocs\u002Foverview\u002Fproviders","Providers"," — build the services your controllers depend on.",[254,1349,1350,1354,1355,267],{},[609,1351,1353],{"href":1352},"\u002Fdocs\u002Foverview\u002Fguards","Guards"," — protect routes with ",[72,1356,1357],{},"#[use_guards]",[254,1359,1360,1364],{},[609,1361,1363],{"href":1362},"\u002Fdocs\u002Foverview\u002Fpipes","Pipes"," — transform and validate inputs.",{"title":12,"searchDepth":13,"depth":14,"links":1366},[1367,1371,1372,1376,1377,1378],{"id":17,"depth":13,"text":18,"children":1368},[1369,1370],{"id":21,"depth":14,"text":22},{"id":24,"depth":14,"text":25},{"id":27,"depth":13,"text":28},{"id":30,"depth":13,"text":31,"children":1373},[1374,1375],{"id":34,"depth":14,"text":35},{"id":37,"depth":14,"text":38},{"id":40,"depth":13,"text":41},{"id":43,"depth":13,"text":44},{"id":46,"depth":13,"text":47},"https:\u002F\u002Fgithub.com\u002Fj4flmao\u002Fferrite_rs\u002Fedit\u002Fmain\u002Fdocs\u002Fcontent\u002Foverview\u002Fcontrollers.md",{"title":1381,"slug":1382},"First steps","overview\u002Ffirst-steps",{"title":1346,"slug":1384},"overview\u002Fproviders",1789565439372]