11use  proc_macro:: TokenStream ; 
22use  quote:: quote; 
33
4- /// TODO 
4+ /// Marks an `async fn` as an HTTP component entrypoint for Spin. 
5+ /// 
6+ /// The `#[http_component]` attribute designates an asynchronous function as the 
7+ /// handler for incoming HTTP requests in a Spin component using the WASI Preview 3 
8+ /// (`wasip3`) HTTP ABI.   
9+ /// 
10+ /// When applied, this macro generates the necessary boilerplate to export the 
11+ /// function to the Spin runtime as a valid HTTP handler. The function must be 
12+ /// declared `async` and take a single argument implementing 
13+ /// [`FromRequest`](::spin_sdk::http_wasip3::FromRequest), typically 
14+ /// [`Request`](::spin_sdk::http_wasip3::Request), and must return a type that 
15+ /// implements [`IntoResponse`](::spin_sdk::http_wasip3::IntoResponse). 
16+ /// 
17+ /// # Requirements 
18+ /// 
19+ /// - The annotated function **must** be `async`. 
20+ /// - The function’s parameter type must implement [`FromRequest`]. 
21+ /// - The return type must implement [`IntoResponse`]. 
22+ /// 
23+ /// If the function is not asynchronous, the macro emits a compile-time error. 
24+ /// 
25+ /// # Generated Code 
26+ /// 
27+ /// The macro expands into a module containing a `Spin` struct that implements the 
28+ /// WASI `http.handler/Guest` interface, wiring the annotated function as the 
29+ /// handler’s entrypoint. This allows the function to be invoked automatically 
30+ /// by the Spin runtime when HTTP requests are received. 
531#[ proc_macro_attribute]  
632pub  fn  http_component ( _attr :  TokenStream ,  item :  TokenStream )  -> TokenStream  { 
733    let  func = syn:: parse_macro_input!( item as  syn:: ItemFn ) ; 
@@ -27,7 +53,7 @@ pub fn http_component(_attr: TokenStream, item: TokenStream) -> TokenStream {
2753
2854            impl  :: spin_sdk:: http_wasip3:: wasip3:: exports:: http:: handler:: Guest  for  self :: Spin  { 
2955                async  fn  handle( request:  :: spin_sdk:: http_wasip3:: wasip3:: http:: types:: Request )  -> Result <:: spin_sdk:: http_wasip3:: wasip3:: http:: types:: Response ,  :: spin_sdk:: http_wasip3:: wasip3:: http:: types:: ErrorCode > { 
30-                     let  request = <:: spin_sdk:: http_wasip3:: IncomingRequest  as  :: spin_sdk:: http_wasip3:: FromRequest >:: from_request( request) ?; 
56+                     let  request = <:: spin_sdk:: http_wasip3:: Request  as  :: spin_sdk:: http_wasip3:: FromRequest >:: from_request( request) ?; 
3157                    :: spin_sdk:: http_wasip3:: IntoResponse :: into_response( super :: #func_name( request) . await ) 
3258                } 
3359            } 
0 commit comments