by cabalamat · 7y ago · 0 comments
@app.route("/<name>/<id>/index.html")
def index(name, id):
return form("Hello {}! id:{}", name, id)
This has the advantages that: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.
#[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... [derive(Deserialize)]
struct HelloWorldParams {
id: String,
name: String,
}
fn index(info: web::Path<HelloWorldParams>) -> impl Responder {
format!("Hello {}! id:{}", info.name, info.id)
}