pub fn proxy_http_fetch<URL: ToString>(
url: URL,
public_key: Option<String>,
options: Option<HttpFetchOptions>,
) -> HttpFetchResponseExpand description
Makes an HTTP request through the proxy service
§Panics
Panics if the serialization of the ProxyHttpFetchAction fails or if the deserialization of the response fails.
We expect these to never happen in practice, as the SDK is designed to ensure valid inputs.
§Examples
use seda_sdk_rs::bytes::ToBytes;
use seda_sdk_rs::proxy_http_fetch::proxy_http_fetch;
use seda_sdk_rs::http::{HttpFetchOptions, HttpFetchMethod};
use std::collections::BTreeMap;
// Basic GET request
let response = proxy_http_fetch("https://api.example.com/data", None, None);
if response.is_ok() {
println!("Status: {}", response.status);
println!("Body length: {}", response.content_length);
}
// POST request with custom options
let mut headers = BTreeMap::new();
headers.insert("Content-Type".to_string(), "application/json".to_string());
let options = HttpFetchOptions {
method: HttpFetchMethod::Post,
headers,
body: Some(serde_json::to_vec(&serde_json::json!({"key": "value"})).unwrap().to_bytes()),
timeout_ms: None,
};
let response = proxy_http_fetch(
"https://api.example.com/data",
Some("02452f1c0a2753c6d2e55da4abeb1b6115c595eec9b0e237b8aaa74913ad3f1dc7".to_string()),
Some(options)
);
// Check response
if response.is_ok() {
// Access response data
println!("Status: {}", response.status);
println!("Final URL: {}", response.url);
println!("Response size: {}", response.content_length);
// Access response headers
if let Some(content_type) = response.headers.get("content-type") {
println!("Content-Type: {}", content_type);
}
}