LoginSignup
1
0

More than 5 years have passed since last update.

【Rust】Rocketで複数ルーティング

Last updated at Posted at 2018-04-23

概要

HelloWorldが終わったので、さてもう少しやってみるか、となった時に複数ルーティングの仕方がわからなかったのでメモ。誰かの助けになればと思います。

やったこと

ルーティングの条件を.mount()でつないでlaunch()は最後で一回だけ呼ぶ。

#![feature(plugin)]
#![plugin(rocket_codegen)]

extern crate rocket;

#[get("/world")]
fn world() -> &'static str {
    "Hello, world from routing!"
}

#[get("/")]
fn hello() -> &'static str {
    "Hello, world!"
}

fn main() {
    // 悪い例
    // rocket::ignite().mount("/", routes![hello]).launch();
    // rocket::ignite().mount("/hello", routes![world]).launch();

    // 良い例
    rocket::ignite().mount("/", routes![hello])
                    .mount("/hello", routes![world]).launch();
}

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0