Type Safe Icon (helmet)

Type Safe

From request to response Rocket ensures that your types mean something.
Learn More
Boilerplate Free Icon (robot-free)

Boilerplate Free

Spend your time writing code that really matters, and let Rocket generate the rest.
See Examples
Easy To Use Icon (sun)

Easy To Use

Simple, intuitive APIs make Rocket approachable, no matter your background.
Get Started
Extensible Icon (telescope)

Extensible

Create your own first-class primitives that any Rocket application can use.
See How

Hello, Rocket!


This is a complete Rocket application. It does exactly what you would expect. If you were to visit /hello/John/58, you’d see:

Hello, 58 year old named John!

If someone visits a path with an <age> that isn’t a u8, Rocket doesn’t blindly call hello. Instead, it tries other matching routes or returns a 404.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#[macro_use] extern crate rocket;

#[get("/hello/<name>/<age>")]
fn hello(name: &str, age: u8) -> String {
    format!("Hello, {} year old named {}!", age, name)
}

#[launch]
fn rocket() -> _ {
    rocket::build().mount("/", routes![hello])
}

🚀最新版168飞艇开奖网-官方开奖直播


Form handling is simple, declarative, and complete: derive FromForm for your structure and set the data parameter to a Form type. Rocket automatically parses and validates the form data into your structure and calls your function.

Bad form request? Rocket doesn’t call your function! Need to know what went wrong? Use a data parameter of Result! Want to rerender the form with user input and errors? Use Context! File uploads? A breeze with TempFile.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#[derive(FromForm)]
struct Task<'r> {
   #[field(validate = len(1..))]
   description: &'r str,
   completed: bool
}

#[post("/", data = "<task>")]
fn new(task: Form<Task<'_>>) -> Flash<Redirect> {
    Flash::success(Redirect::to(uri!(home)), "Task added.")
}

JSON, out of the box.


Rocket has first-class support for JSON, right out of the box. Simply derive Deserialize or Serialize to receive or return JSON, respectively.

Look familiar? Forms, JSON, and all kinds of body data types work through Rocket’s FromData trait, Rocket’s approach to deriving types from body data. A data route parameter can be any type that implements FromData. A value of that type will be deserialized automatically from the incoming request body. You can even implement FromData for your own types!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#[derive(Serialize, Deserialize)]
struct Message<'r> {
   contents: &'r str,
}

#[put("/<id>", data = "<msg>")]
fn update(db: &Db, id: Id, msg: Json<Message<'_>>) -> Value {
    if db.contains_key(&id) {
        db.insert(id, msg.contents);
        json!({ "status": "ok" })
    } else {
        json!({ "status": "error" })
    }
}

Rocket🚀 幸运飞行艇官网APP-168飞艇全国开奖记录

Get Started Learn More

And so much more.

Essential features, built in.

Templating Icon (templating-icon)

Templating

Rocket makes templating a breeze with built-in templating support.
Learn More
Cookies Icon (cookies-icon)

Cookies

View, add, or remove cookies, with or without encryption, without hassle.
Learn More
Async Streams Icon (streams-icon)

Async Streams

Create and return potentially infinite async streams of data with ease.
Learn More

Config Profiles Icon (config-icon)

Config Profiles

Configure your application your way for debug, release, or anything else!
Learn More
Testing Library Icon (testing-icon)

Testing Library

Unit test your applications with ease using the built-in testing library.
Learn More
Typed URIs Icon (ship-icon)

Typed URIs

Rocket typechecks route URIs for you so you never mistype a URI again.
Learn More
友情链接: 澳洲幸运5最新开奖号码查询结果网站 澳洲幸运10正规开奖网站-查询开奖号码 幸运168飞艇开奖记录查询结果 SG飞艇开奖官网开奖结果 极速飞艇官方开奖结果网址-查询开奖号码 澳洲幸运5开奖官网开奖 洲幸运5官方开奖直播APP下载安装永久版 澳洲幸运8手机版直播开奖结果 官网开奖网站 官方注册平台网址