use crate::api::schema::*;
use serde_json::{Value};
use std::collections::HashMap;
+use std::sync::Arc;
type ApiHandlerFn = fn(Value, &ApiMethod) -> Result<Value, Error>;
pub struct ApiMethod {
pub parameters: ObjectSchema,
- pub returns: Schema,
+ pub returns: Arc<Schema>,
pub handler: ApiHandlerFn,
}
Self {
parameters,
handler,
- returns: Schema::Null,
+ returns: Arc::new(Schema::Null),
}
}
+ pub fn returns<S: Into<Arc<Schema>>>(mut self, schema: S) -> Self {
+
+ self.returns = schema.into();
+
+ self
+ }
+
}
pub enum SubRoute {
}))
}
-
pub fn router() -> Router {
let route4 = Router::new()
- .get(ApiMethod {
- parameters: ObjectSchema::new("Another Endpoint."),
- returns: Schema::Null,
- handler: |param, _info| {
+ .get(ApiMethod::new(
+ |param, _info| {
println!("This is a clousure handler: {}", param);
Ok(json!(null))
- },
- });
+ },
+ ObjectSchema::new("Another Endpoint."))
+ .returns(Schema::Null));
let nodeinfo = Router::new()
ObjectSchema::new("Proxmox Backup Server API version.")));
let route = Router::new()
- .get(ApiMethod {
- handler: get_version,
- parameters: ObjectSchema::new("Directory index."),
- returns: Schema::Null,
- })
+ .get(ApiMethod::new(
+ get_version,
+ ObjectSchema::new("Directory index.")))
.subdir("version", version)
.subdir("nodes", nodes);