2

Nickel states that you can use variables in the URLs, which sounds very useful, but is it possible to use multiple variables?

Something like:

www.example.com/login/:userid?:apikey?:etc

server.get("/start/:userid?:passwd", middleware! { |request|
    // format!("This is user: {:?} = {:?}",
    // request.param("userid"),
    // request.param("passwd")
    // );
});
user3816764
  • 489
  • 5
  • 22

1 Answers1

2

You need a separator. For example:

#[macro_use] extern crate nickel;

use nickel::Nickel;

fn main() {
    let mut server = Nickel::new();

    server.utilize(router! {
        get "/start/:userid/:passwd" => |request, _response| {
            println!("this is user: {:?} = {:?}",
                     request.param("userid"),
                     request.param("passwd")
                    );

            "Hello world!"
        }
    });

    server.listen("127.0.0.1:6767");
}

It looks from your question like you might be expecting passwd as some sort of query parameter, rather than in the URL, though.

I would caution you against creating a session with GET, and you should be using POST instead.

Steve Klabnik
  • 14,521
  • 4
  • 58
  • 99
  • Oh, haha, it was just example text. I wouldn't send a password like that, don't worry :P Why POST over GET? I'm not overly familiar with this sort of thing. – user3816764 Jun 19 '15 at 23:57
  • see http://stackoverflow.com/questions/504947/when-should-i-use-get-or-post-method-whats-the-difference-between-them and its answers – Steve Klabnik Jun 20 '15 at 06:10