curl_json

Function curl_json 

Source
pub fn curl_json(url: &str) -> Result<Value, Box<dyn Error + Send + Sync>>
Expand description

What: Fetch JSON from a URL using curl and parse into serde_json::Value.

Inputs:

  • url: HTTP(S) URL to request

Output:

  • Ok(Value) on success; Err if curl fails or the response is not valid JSON

ยงErrors

  • Returns Err when curl command execution fails (I/O error or curl not found)
  • Returns Err when curl exits with non-zero status (network errors, HTTP errors, timeouts)
  • Returns Err when response body cannot be decoded as UTF-8
  • Returns Err when response body cannot be parsed as JSON

Details:

  • Executes curl with appropriate flags and parses the UTF-8 body with serde_json.
  • On Windows, uses -k flag to skip SSL certificate verification.
  • Provides user-friendly error messages for common curl failure cases.
  • For HTTP errors, includes the actual status code in the error message when available.