Compare commits
No commits in common. "6fa76062265189c8aa0590b02128bfc298ec5a61" and "147186f8dc1a1ef93bf1d81d29ae68eafa752953" have entirely different histories.
6fa7606226
...
147186f8dc
3 changed files with 3 additions and 15 deletions
|
@ -11,10 +11,6 @@ url = "https://api.alemi.dev/"
|
||||||
url = "https://api.alemi.dev/look/into/the/void"
|
url = "https://api.alemi.dev/look/into/the/void"
|
||||||
extract = { type = "discard" }
|
extract = { type = "discard" }
|
||||||
|
|
||||||
[route.notfound]
|
|
||||||
url = "https://api.alemi.dev/not-found"
|
|
||||||
expect = 404
|
|
||||||
|
|
||||||
[route.debug]
|
[route.debug]
|
||||||
url = "https://api.alemi.dev/debug"
|
url = "https://api.alemi.dev/debug"
|
||||||
method = "PUT"
|
method = "PUT"
|
||||||
|
|
|
@ -37,9 +37,6 @@ pub enum PostWomanError {
|
||||||
#[error("invalid regex: {0:?}")]
|
#[error("invalid regex: {0:?}")]
|
||||||
InvalidRegex(#[from] regex::Error),
|
InvalidRegex(#[from] regex::Error),
|
||||||
|
|
||||||
#[error("request didn't match expected status code: {0:?}")]
|
|
||||||
UnexpectedStatusCode(reqwest::Response),
|
|
||||||
|
|
||||||
#[error("invalid Json Query: {0}")]
|
#[error("invalid Json Query: {0}")]
|
||||||
JQError(String),
|
JQError(String),
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,6 @@ pub struct Endpoint {
|
||||||
pub headers: Option<Vec<String>>,
|
pub headers: Option<Vec<String>>,
|
||||||
/// body, optional string
|
/// body, optional string
|
||||||
pub body: Option<StringOr<toml::Table>>,
|
pub body: Option<StringOr<toml::Table>>,
|
||||||
/// expected error code, will fail if different
|
|
||||||
pub expect: Option<u16>,
|
|
||||||
/// response extractor
|
/// response extractor
|
||||||
pub extract: Option<StringOr<Extractor>>,
|
pub extract: Option<StringOr<Extractor>>,
|
||||||
}
|
}
|
||||||
|
@ -137,11 +135,8 @@ impl Endpoint {
|
||||||
.headers(headers)
|
.headers(headers)
|
||||||
.body(body)
|
.body(body)
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?
|
||||||
|
.error_for_status()?;
|
||||||
if res.status().as_u16() != self.expect.unwrap_or(200) {
|
|
||||||
return Err(PostWomanError::UnexpectedStatusCode(res));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(match self.extract.unwrap_or_default() {
|
Ok(match self.extract.unwrap_or_default() {
|
||||||
StringOr::T(Extractor::Discard) => "".to_string(),
|
StringOr::T(Extractor::Discard) => "".to_string(),
|
||||||
|
@ -186,7 +181,7 @@ async fn format_body(res: reqwest::Response) -> Result<String, PostWomanError> {
|
||||||
None => Ok(res.text().await? + "\n"),
|
None => Ok(res.text().await? + "\n"),
|
||||||
Some(v) => match v.to_str()? {
|
Some(v) => match v.to_str()? {
|
||||||
"application/json" => Ok(serde_json::to_string_pretty(&res.json::<serde_json::Value>().await?)? + "\n"),
|
"application/json" => Ok(serde_json::to_string_pretty(&res.json::<serde_json::Value>().await?)? + "\n"),
|
||||||
"text/plain" | "text/html" => Ok(res.text().await? + "\n"),
|
"text/plain" => Ok(res.text().await? + "\n"),
|
||||||
_ => Ok(format!("base64({})\n", BASE64_STANDARD.encode(res.bytes().await?))),
|
_ => Ok(format!("base64({})\n", BASE64_STANDARD.encode(res.bytes().await?))),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue