rustful是Rust编程语言的一个RESTful框架,主要目的是创建一个简单、轻量级的HTTP服务应用基础。基于无状态结构,根据路径和HTTP方法映射到响应处理器。
示例代码:
//Iclude rustful_macros durig sytax phase to be able to use the macros#![feature(phase)]#[phase(plugi)]exter crate rustful_macros;exter crate rustful;exter crate http;use rustful::{Server, Request, Respose};use http::method::Get;///Our hadler fuctiof hadler(request: Request, respose: &mut Respose) { //Sed somethig ice to the user try_sed!(respose, "Hello, user! It looks like this server works fie." while "sedig hello");}f mai() { let server = Server::ew(8080, router!{"/" => Get: hadler}); //Start the server. All code beyod this poit is ureachable server.ru();}
评论