#![allow(clippy::result_large_err)]
use std::sync::Arc;
use lino_rest_api::{
CorsPolicy, MemoryStore, ResourceOptions, ServiceInfo, boolean, create_lino_app, object, serve,
string,
};
#[tokio::main]
async fn main() -> std::io::Result<()> {
let address = std::env::args()
.nth(1)
.unwrap_or("0.0.0.0:8000".to_string());
let mut app = create_lino_app()
.with_info(
ServiceInfo::new("Tasks API", "1.0.0")
.describing("A task list served as Links Notation instead of JSON"),
)
.with_cors(CorsPolicy::permissive());
let tasks = Arc::new(MemoryStore::seeded([object([
("title", string("Write the specification")),
("done", boolean(true)),
])]));
app.resource("/tasks", tasks, ResourceOptions::new().with_name("task"));
app.get_fn("/health", "Liveness probe", |_request| {
Ok(object([("status", string("ok"))]))
});
println!("Serving the Tasks API on http://{address}");
serve(app, &address).await
}