| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
10年前发布

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();  }

项目主页:http://www.open-open.com/lib/view/home/1413422818200

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1413422818200.html
rustful WEB服务/RPC/SOA