Re:Actix-web 1.0 – A small, pragmatic, and fast web framewor...
by killercup on Wednesday June 05, 2019 @04:59PM
(#20109073)
I can't speak for the actix-web maintainers but I did find this in their examples:
#[get("/resource1/{name}/index.html")]
fn index(req: HttpRequest, name: web::Path<String>) -> String {
println!("REQ: {:?}", req);
format!("Hello: {}!\r\n", name)
}
see https://github.com/actix/actix-web/blob/e399e01a22b8a848ecbb...
Re:Actix-web 1.0 – A small, pragmatic, and fast web framewor...
by JoeCamel on Thursday June 06, 2019 @03:53AM
(#20112445)
I've just run it and it works! I didn't know about the macro.
Re:Actix-web 1.0 – A small, pragmatic, and fast web framewor...
by munmaek on Friday June 07, 2019 @01:22AM
(#20121861)
The thing with actix's web stuff is that things like these are just not well documented yet.
I also had no idea about this macro until I was digging through documentation for something else.
Re:Actix-web 1.0 – A small, pragmatic, and fast web framewor...
by tracker1 on Wednesday June 05, 2019 @06:10PM
(#20109665)
Might want to give rocket a look, as it's closer to what you're describing. The raw numbers aren't in line with actix-web, but definitely an interesting project. Just starting to get my toes wet with Rust, so not as familiar as some here.
Re:Actix-web 1.0 – A small, pragmatic, and fast web framewor...
by lemmox on Wednesday June 05, 2019 @05:05PM
(#20109135)
That syntax refers to fields in a tuple. Path parameters can be deserialized into a type like this:
[derive(Deserialize)]
struct HelloWorldParams {
id: String,
name: String,
}
fn index(info: web::Path<HelloWorldParams>) -> impl Responder {
format!("Hello {}! id:{}", info.name, info.id)
}
1. the endpoint "/<name>/<id>/index.html" goes in the code right above the function that implements it.
2. the variables are called `name` and `id` and not `info.0` and `info.1` which is a less informative naming convention.