feat: handle query params
This commit is contained in:
parent
6fe5cefc4a
commit
afc582b0a6
2 changed files with 17 additions and 1 deletions
|
@ -15,6 +15,10 @@ headers = [
|
||||||
"Content-Type: application/json",
|
"Content-Type: application/json",
|
||||||
"Authorization: Bearer ${PW_TOKEN}",
|
"Authorization: Bearer ${PW_TOKEN}",
|
||||||
]
|
]
|
||||||
|
query = [
|
||||||
|
"body=json",
|
||||||
|
"cache=0"
|
||||||
|
]
|
||||||
body = { hello = "world!", success = true }
|
body = { hello = "world!", success = true }
|
||||||
extract = { type = "body" }
|
extract = { type = "body" }
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,13 @@ impl Endpoint {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Some(query) = self.query {
|
||||||
|
self.query = Some(
|
||||||
|
query.into_iter()
|
||||||
|
.map(|x| x.replace(&k_var, &v))
|
||||||
|
.collect()
|
||||||
|
);
|
||||||
|
}
|
||||||
if let Some(headers) = self.headers {
|
if let Some(headers) = self.headers {
|
||||||
self.headers = Some(
|
self.headers = Some(
|
||||||
headers.into_iter()
|
headers.into_iter()
|
||||||
|
@ -101,12 +108,17 @@ impl Endpoint {
|
||||||
StringOr::T(json) => serde_json::to_string(&json)?,
|
StringOr::T(json) => serde_json::to_string(&json)?,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut url = self.url;
|
||||||
|
if let Some(query) = self.query {
|
||||||
|
url = format!("{url}?{}", query.join("&"));
|
||||||
|
}
|
||||||
|
|
||||||
let client = reqwest::Client::builder()
|
let client = reqwest::Client::builder()
|
||||||
.user_agent(opts.user_agent.as_deref().unwrap_or(APP_USER_AGENT))
|
.user_agent(opts.user_agent.as_deref().unwrap_or(APP_USER_AGENT))
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
let res = client
|
let res = client
|
||||||
.request(method, self.url)
|
.request(method, url)
|
||||||
.headers(headers)
|
.headers(headers)
|
||||||
.body(body)
|
.body(body)
|
||||||
.send()
|
.send()
|
||||||
|
|
Loading…
Reference in a new issue