Why am I getting this error with reqwest API?

Newbie here. I'm trying to make an HTTP request with reqwest crate. I use the latest version: reqwest = {version = "0.11.6", features = ["blocking"]}.

The minimal code reproducing the problem:

extern crate maplit;
use reqwest;

fn main() {
	let query = hashmap!("annotations" => "nodes", "overview" => "full");
	let client = reqwest::blocking::Client::new();
	let res = client.get("http://localhost:5000/route/v1/driving/39.1816407,21.511005;39.1816407,21.511005").query(&query).send();

	println!("{:?}", res);


Ok(Response { url: Url { scheme: "http", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("localhost")), port: Some(5000), path: "/route/v1/driving/39.1816407,21.511005;39.1816407,21.511005", query: Some("annotations=nodes&overview=full"), fragment: None }, status: 200, headers: {"access-control-allow-origin": "*", "access-control-allow-methods": "GET", "access-control-allow-headers": "X-Requested-With, Content-Type", "content-type": "application/json; charset=UTF-8", "content-disposition": "inline; filename="response.json"", "content-length": "693", "connection": "keep-alive", "keep-alive": "timeout=5, max=512"} })

When I put a ? after send, it raises an error:

error: src/main.rs:9: the `?` operator can only be used
in a function that returns `Result` or `Option`
(or another type that implements `Try`)

The docs say you can put a ? after send.

pub fn send(self) -> Result<Response>

It clearly returns a Result type.
Plenty of examples from the docs show ? used:

let res = client.get("https://www.rust-lang.org")
	.header(USER_AGENT, "foo")

What am I doing wrong?

Your main function does not return a Result.


Ok, now I see which function it meant. It worked, thanks!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.