Rust 的 RESTful 框架:rustful
rustful 是 Rust 編程語言的一個 RESTful 框架,主要目的是創建一個簡單、輕量級的 HTTP 服務應用基礎。它是基于一個無狀態的結構,其中響應處理程序分配給路徑和HTTP方法,這自然使得它能夠在計算機集群中的一個服務器或多個實例同時運行。
一些特性:
- Generic response handlers. Just implement the Handler trait and you are done.
- Optional resource cache with lazy loading and simple cleaning of unused data.
- Some handy macros reduces risk for typos and makes life easier.
- Variables and recursive wildcards in routes.
- Minimal routing overhead.
示例代碼:
//Include rustful_macros during syntax phase to be able to use the macros #![feature(phase)] #[phase(plugin)] extern crate rustful_macros; extern crate rustful; extern crate http; use rustful::{Server, Request, Response}; use http::method::Get; ///Our handler function fn handler(request: Request, response: &mut Response) { //Send something nice to the user try_send!(response, "Hello, user! It looks like this server works fine." while "sending hello"); } fn main() { let server = Server::new(8080, router!{"/" => Get: handler}); //Start the server. All code beyond this point is unreachable server.run(); }
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!