Rust​ 的微框架 Pencil Framework

码农软件 · 软件分类 · 微服务框架 · 2019-03-18 11:12:46

软件介绍

Pencil Framework 是一个 Rust 的微框架,其灵感来自于 Flask

一个简单应用:

extern crate pencil;

use pencil::{Pencil, Request, Response, PencilResult};

fn hello(_: &mut Request) -> PencilResult {
    Ok(Response::from("Hello World!"))
}

fn main() {
    let mut app = Pencil::new("/web/hello");
    app.get("/", "hello", hello);
    app.run("127.0.0.1:5000");
}

路由:

fn user(r: &mut Request) -> PencilResult {
    let user_id = r.view_args.get("user_id").unwrap();
    Ok(format!("user {}", user_id).into())
}

fn main() {
    // app here
    app.get("/user/<int:user_id>", "user", user);
}

JSON 处理:

use std::collections::BTreeMap;
use pencil::jsonify;

fn app_info(_: &mut Request) -> PencilResult {
    let mut d = BTreeMap::new();
    d.insert("name", "hello");
    d.insert("version", "0.1.0");
    return jsonify(&d);
}

fn main() {
    // app here
    app.get("/info", "app_info", app_info);
}

错误处理:

use pencil::HTTPError;

fn page_not_found(_: HTTPError) -> PencilResult {
    let mut response = Response::from("Customized 404 :)");
    response.status_code = 404;
    Ok(response)
}

fn main() {
    // app here
    app.httperrorhandler(404, page_not_found);
}

本文地址:https://codercto.com/soft/d/1608.html

Head First EJB(中文版)

Head First EJB(中文版)

KathySierra,Ber / 中国电力出版社 / 2006-9 / 79.00元

有些人只是想通过认证来取悦挑剔的老板,但相信你不是这种人。确实,你也想通过Su n认证业务组件开发人员(SCBCD)考试,但不仅如此,你还需要真正把EJB用到实处。你要构建应用,要对付最后期限,如果通过考试之后第二天早上就把你学过的EJB知识忘得一干二净,你肯定会受不了。 我们会看着你稳稳当当地通过考试,而且会帮你在实际中使用EJB。你会深入地了解EJB体系结构、会话、实体和消息驱动......一起来看看 《Head First EJB(中文版)》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

URL 编码/解码
URL 编码/解码

URL 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具