use serde::{Deserialize, Serialize};
use server_less::server;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Item {
pub id: u32,
pub name: String,
}
#[derive(Clone)]
pub struct ItemService;
#[server]
impl ItemService {
pub fn list_items(&self) -> Vec<Item> {
vec![
Item {
id: 1,
name: "Widget".into(),
},
Item {
id: 2,
name: "Gadget".into(),
},
]
}
pub fn create_item(&self, name: String) -> Item {
Item { id: 42, name }
}
pub fn get_item(&self, item_id: u32) -> Option<Item> {
if item_id == 1 {
Some(Item {
id: 1,
name: "Widget".into(),
})
} else {
None
}
}
}
#[tokio::main]
async fn main() {
println!("Starting server on http://localhost:3000");
println!(" GET /items - list items");
println!(" POST /items - create item");
println!(" GET /items/{{id}} - get item by ID");
println!(" GET /health - health check");
ItemService.serve("0.0.0.0:3000").await.unwrap();
}