Files
waggle-os/app/src-tauri/src/commands/http.rs
shumeiko.it 4c1b404339 refactor(app): remove the wiki Tauri commands (P2.2)
get_wiki_pages, get_wiki_page, get_wiki_page_content and
compile_wiki_section proxied to the sidecar's /api/wiki routes, which
served the wiki-compiler package and left with the old memory engine in
P1.5. No screen called them. Remove the commands, their TypeScript
bindings and tests. cargo check and the 32 Rust tests pass.
2026-11-01 00:42:39 +01:00

41 lines
1.2 KiB
Rust

// Shared HTTP helpers for sidecar-proxy commands. Command modules import
// from here rather than reimplementing.
use serde_json::Value;
const SIDECAR_HOST: &str = "127.0.0.1";
pub fn sidecar_url(port: u16, path: &str) -> String {
format!("http://{}:{}{}", SIDECAR_HOST, port, path)
}
pub async fn http_get(url: &str) -> Result<reqwest::Response, String> {
reqwest::get(url)
.await
.map_err(|e| format!("HTTP GET {} failed: {}", url, e))
}
pub async fn http_post(url: &str, body: &Value) -> Result<reqwest::Response, String> {
let client = reqwest::Client::new();
client
.post(url)
.json(body)
.send()
.await
.map_err(|e| format!("HTTP POST {} failed: {}", url, e))
}
pub async fn parse_json(resp: reqwest::Response) -> Result<Value, String> {
let status = resp.status();
if !status.is_success() {
let body_text = resp
.text()
.await
.unwrap_or_else(|_| "<unreadable body>".to_string());
return Err(format!("sidecar returned {}: {}", status, body_text));
}
resp.json::<Value>()
.await
.map_err(|e| format!("sidecar returned non-JSON body: {}", e))
}