From afc582b0a6d6a91bedaa550e173db06dfdf35a06 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 19 Oct 2024 19:24:12 +0200 Subject: [PATCH] feat: handle query params --- postwoman.toml | 4 ++++ src/model/endpoint.rs | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/postwoman.toml b/postwoman.toml index 324b327..cad111c 100644 --- a/postwoman.toml +++ b/postwoman.toml @@ -15,6 +15,10 @@ headers = [ "Content-Type: application/json", "Authorization: Bearer ${PW_TOKEN}", ] +query = [ + "body=json", + "cache=0" +] body = { hello = "world!", success = true } extract = { type = "body" } diff --git a/src/model/endpoint.rs b/src/model/endpoint.rs index 256e4ec..61d5589 100644 --- a/src/model/endpoint.rs +++ b/src/model/endpoint.rs @@ -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 { self.headers = Some( headers.into_iter() @@ -101,12 +108,17 @@ impl Endpoint { 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() .user_agent(opts.user_agent.as_deref().unwrap_or(APP_USER_AGENT)) .build()?; let res = client - .request(method, self.url) + .request(method, url) .headers(headers) .body(body) .send()