diff --git a/src/api/router.rs b/src/api/router.rs index d0e475da..c86c8273 100644 --- a/src/api/router.rs +++ b/src/api/router.rs @@ -8,7 +8,7 @@ pub struct ApiMethod { pub description: &'static str, pub parameters: Schema, pub returns: Schema, - pub handler: fn(Value, &ApiMethod) -> Result, + pub handler: Box Result + Send + Sync>, } pub enum SubRoute { diff --git a/src/api/server.rs b/src/api/server.rs index 889c3a92..c8162995 100644 --- a/src/api/server.rs +++ b/src/api/server.rs @@ -173,7 +173,7 @@ fn handle_sync_api_request( tokio::spawn(task); */ - let res = (info.handler)(params, info)?; + let res = (*info.handler)(params, info)?; Ok(res) diff --git a/src/api3.rs b/src/api3.rs index 752793a2..805e3414 100644 --- a/src/api3.rs +++ b/src/api3.rs @@ -25,25 +25,23 @@ fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result Result { - println!("This is a subdir {}", param); - - Ok(json!(null)) -} - pub fn router() -> Router { let route3 = Router::new() .get(ApiMethod { - handler: test_subdir_api_handler, description: "Another Endpoint.", parameters: parameter!{}, returns: Schema::Null, + handler: Box::new(|param, _info| { + println!("This is a clousure handler: {}", param); + + Ok(json!(null)) + }) }); let route2 = Router::new() .get(ApiMethod { - handler: test_sync_api_handler, + handler: Box::new(test_sync_api_handler), description: "This is a simple test.", parameters: parameter!{ force => Boolean!{