January 2019
Intermediate to advanced
520 pages
14h 32m
English
To make GET requests, we will use the test_get function, which creates a Client of the reqwest crate, sets a path, executes a send request, and deserializes the response from JSON:
fn test_get<T>(path: &str) -> Twhere T: for <'de> Deserialize<'de>,{ let client = Client::new(); let data = client.get(&test_url(path)) .send() .unwrap() .text() .unwrap(); serde_json::from_str(&data).unwrap()}
If you are familiar with the reqwest crate, you may ask why we get text values, since Client has the json method that deserializes JSON? If we do that, we can't see the original value if we have deserialization issues, but using the original text of a response, we can log it for investigation.
To generate URLs, we use the following function: ...
Read now
Unlock full access