cURL to Rust (reqwest & tokio) Code Generator
Transform cURL commands into idiomatic, asynchronous Rust HTTP requests using reqwest, serde_json, custom headers, and tokio runtime.
//! cURL to Rust HTTP Client generated by ToolsAA (reqwest & tokio)
//! Zero-server-upload client-side generation, memory safe and asynchronous.
use reqwest::Client;
use serde::{Deserialize, Serialize};
// ============================================================================
// TYPE-SAFE DATA MODELS (Serde derive)
// ============================================================================
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MessagItem {
pub role: String,
pub content: String,
}
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RequestPayload {
pub model: String,
pub temperature: f64,
pub max_tokens: i64,
pub stream: bool,
pub messages: Vec<MessagItem>,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Thread-safe reqwest client with internal connection pooling
let client = Client::new();
// Construct typed Rust request payload
let payload = RequestPayload {
model: "gpt-4o".to_string(),
temperature: 0.7,
max_tokens: 1024,
stream: false,
messages: vec![
MessagItem {
role: "system".to_string(),
content: "You are an expert Rust systems programmer.".to_string(),
},
MessagItem {
role: "user".to_string(),
content: "Explain zero-cost abstractions in reqwest and tokio.".to_string(),
}
],
};
// Build and dispatch HTTP request
let response = client.post("https://api.openai.com/v1/chat/completions")
.bearer_auth("sk-proj-1234567890abcdef")
.json(&payload)
.send()
.await?;
// Inspect HTTP status code
let status = response.status();
println!("Status Code: {}", status);
// Parse response body as structured JSON
let json_body: serde_json::Value = response.json().await?;
println!("Response JSON:\n{:#}", json_body);
Ok(())
}100% Client-Side Transpilation
All cURL parsing, argument tokenization, and Rust code generation happen entirely within your browser memory. No credentials or endpoints ever touch an external server.
Async Tokio & reqwest Idioms
Generates modern, asynchronous Rust code using reqwest and the Tokio runtime, featuring ergonomic builder methods, structured headers, and clean error propagation with the ? operator.
Cargo.toml & Full Flag Parity
Automatically synthesizes required Cargo.toml crate dependencies and features, supporting query parameters, Bearer tokens, Basic Auth (-u), multipart forms, timeouts, and custom TLS.