January 2019
Intermediate to advanced
520 pages
14h 32m
English
The HTTP URI can contain a query string with parameters that we can use to tune a request. The Request type has a method, uri, which returns a query string if it's available. We added the queryst crate, which parses a query string to serde_json::Value. We'll use this value to extract the "format" parameters from the query string. If the format isn't provided, we'll use "json" as a default value. Add the format-extracting block to the branch that handles requests to the /random path and use the serialize function that we previously declared:
(&Method::POST, "/random") => { let format = { let uri = req.uri().query().unwrap_or(""); let query = queryst::parse(uri).unwrap_or(Value::Null); query["format"].as_str().unwrap_or("json").to_string() ...Read now
Unlock full access