How to get data submitted from HTML form that insert into redis database?


#1

I have problem get data from HTML form store value into redis database when user submit. Use Nickel web framework, this is code:

fn save_db<'a>(req: &mut Request, res: Response<'a>) -> MiddlewareResult<'a>{
           let mut server = Nickel::new();
          /* FIXME: connect redis*/ 
          let client = Client::open("redis://127.0.0.1/").unwrap();
          let conn = client.get_connection().unwrap();

          server.post("/confirmation", middleware!{|req, res|
            let mut form_data = String::new();
           req.origin.read_to_string(&mut form_data).unwrap();
          let _: ()= conn.set("contents",form_data).unwrap();
        println!("{}", form_data);
    
         let mut data = HashMap::<&str,String>::new();
        data.insert("content", form_data);
         data.insert("page_title", "Save blog data".to_string());
        return res.render("app/views/blog/save.tpl", &data);
  });
}

    //error: cannot infer an appropriate lifetime for lifetime parameter `'b` due to conflicting requirements [E0495](req.origin.read_to_string(&mut form_data).unwrap();)