Skip to main content

Cli

Struct Cli 

Source
pub struct Cli {
Show 38 fields pub method: Option<String>, pub url: Option<String>, pub header: Vec<String>, pub body: Option<String>, pub body_base64: Option<String>, pub body_file: Option<String>, pub body_multipart: Vec<String>, pub body_urlencoded: Vec<String>, pub response_save_dir: Option<String>, pub response_save_above_bytes: Option<u64>, pub request_concurrency_limit: Option<u64>, pub timeout_connect_s: Option<u64>, pub timeout_idle_s: Option<u64>, pub retry: Option<u32>, pub retry_base_delay_ms: Option<u64>, pub retry_on_status: Option<String>, pub response_redirect: Option<u32>, pub response_parse_json: Option<bool>, pub response_decompress: Option<bool>, pub response_save_file: Option<String>, pub response_save_resume: bool, pub response_max_bytes: Option<u64>, pub chunked: bool, pub chunked_delimiter: Option<String>, pub chunked_delimiter_raw: bool, pub progress_ms: Option<u64>, pub progress_bytes: Option<u64>, pub tls_insecure: bool, pub tls_cacert_file: Option<String>, pub tls_cert_file: Option<String>, pub tls_key_file: Option<String>, pub proxy: Option<String>, pub upgrade: Option<String>, pub output: String, pub log: Option<String>, pub verbose: bool, pub dry_run: bool, pub mode: CliMode,
}
Expand description

Agent-First HTTP — persistent HTTP client for AI agents.

§Modes

  • --mode cli (default): one request, one structured response, then exit
  • --mode pipe: long-lived JSONL stdin/stdout session for agents
  • --mode curl: parse a focused subset of curl flags, then execute through the same runtime

§Output and Exit Codes

  • default output is one JSON object on stdout
  • --output yaml and --output plain only reformat the envelope; server response bodies are not rewritten
  • exit code 0: HTTP response received
  • exit code 1: transport/runtime error
  • exit code 2: invalid arguments

§Request Body Rules

  • --body with a JSON object or array auto-sets Content-Type: application/json
  • string bodies are sent as raw bytes; set --header "Content-Type: ..." yourself when needed
  • --body, --body-base64, --body-file, --body-multipart, and --body-urlencoded are mutually exclusive

§Streaming and Files

  • --chunked emits chunk_start, repeated chunk_data, then chunk_end
  • use --chunked-delimiter '\n\n' for SSE and --chunked-delimiter-raw for binary frames
  • --response-save-file writes the body to disk; --response-save-resume resumes partial downloads
  • progress logs are opt-in via --log progress

§Examples

afhttp GET https://api.example.com/users
afhttp POST https://api.example.com/users --body '{"name":"Alice"}'
afhttp POST https://api.openai.com/v1/files \
  --header "Authorization: Bearer sk-xxx" \
  --body-multipart purpose=assistants \
  --body-multipart file=@/tmp/data.jsonl;filename=data.jsonl;type=application/jsonl
afhttp GET https://api.example.com/stream --chunked-delimiter '\n\n'
afhttp GET https://example.com/large.tar.gz \
  --response-save-file /tmp/large.tar.gz \
  --log progress
afhttp --mode pipe

Fields§

§method: Option<String>

HTTP method (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS)

§url: Option<String>

URL to request

§header: Vec<String>

Request header (repeatable). Format: “Name: Value”. Empty value removes default.

§body: Option<String>

Request body. Valid JSON object/array auto-detected and sets Content-Type: application/json. @path reads from file.

§body_base64: Option<String>

Base64-encoded binary request body

§body_file: Option<String>

Read request body from file

§body_multipart: Vec<String>

Multipart form part (repeatable). Format: name=value or name=@path[;filename=x][;type=mime]

§body_urlencoded: Vec<String>

URL-encoded form field (repeatable). Format: name=value. Sets Content-Type: application/x-www-form-urlencoded.

§response_save_dir: Option<String>

Directory for auto-saved large response bodies

§response_save_above_bytes: Option<u64>

Auto-save response body to response-save-dir when larger than this (default: 10485760)

§request_concurrency_limit: Option<u64>

Max concurrent in-flight requests (0 = unlimited)

§timeout_connect_s: Option<u64>

TCP+TLS handshake timeout in seconds (default: 10)

§timeout_idle_s: Option<u64>

No-data timeout in seconds (default: 30)

§retry: Option<u32>

Retry count (default: 0, no retry)

§retry_base_delay_ms: Option<u64>

Base delay for first retry in ms (default: 100). Subsequent: base * 2^(attempt-1)

§retry_on_status: Option<String>

Comma-separated status codes to retry (e.g. 429,503)

§response_redirect: Option<u32>

Redirect limit (default: 10, 0=disable)

§response_parse_json: Option<bool>

Parse JSON response body (default: true)

§response_decompress: Option<bool>

Auto-decompress response (default: true)

§response_save_file: Option<String>

Save response body to file

§response_save_resume: bool

Resume download if response-save-file exists

§response_max_bytes: Option<u64>

Hard limit on response body size in bytes

§chunked: bool

Stream response in chunks

§chunked_delimiter: Option<String>

Chunk delimiter (default: \n). Use \n\n for SSE. Implies –chunked

§chunked_delimiter_raw: bool

Raw binary chunks (null delimiter). Implies –chunked

§progress_ms: Option<u64>

Time-based progress interval in ms (default: 10000, 0=disable). Works with –progress-bytes

§progress_bytes: Option<u64>

Byte-based progress interval (default: 0=disable). Works with –progress-ms

§tls_insecure: bool

Skip certificate verification

§tls_cacert_file: Option<String>

CA certificate file path

§tls_cert_file: Option<String>

Client certificate file path

§tls_key_file: Option<String>

Client private key file path

§proxy: Option<String>

Proxy URL

§upgrade: Option<String>

Protocol upgrade (e.g. “websocket”)

§output: String

Output format: json (default), yaml (human-readable), plain (logfmt)

§log: Option<String>

Log categories (comma-separated). Categories: startup, request, progress, retry, redirect

§verbose: bool

Enable all log categories (equivalent to –log startup,request,progress,retry,redirect)

§dry_run: bool

Preview the request without executing it

§mode: CliMode

Runtime mode: cli (default), pipe, or curl

Trait Implementations§

Source§

impl Args for Cli

Source§

fn group_id() -> Option<Id>

Report the ArgGroup::id for this set of arguments
Source§

fn augment_args<'b>(__clap_app: Command) -> Command

Append to Command so it can instantiate Self via FromArgMatches::from_arg_matches_mut Read more
Source§

fn augment_args_for_update<'b>(__clap_app: Command) -> Command

Append to Command so it can instantiate self via FromArgMatches::update_from_arg_matches_mut Read more
Source§

impl CommandFactory for Cli

Source§

fn command<'b>() -> Command

Build a Command that can instantiate Self. Read more
Source§

fn command_for_update<'b>() -> Command

Build a Command that can update self. Read more
Source§

impl FromArgMatches for Cli

Source§

fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>

Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
Source§

fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>

Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
Source§

fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>

Assign values from ArgMatches to self.
Source§

fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>

Assign values from ArgMatches to self.
Source§

impl Parser for Cli

Source§

fn parse() -> Self

Parse from std::env::args_os(), exit on error.
Source§

fn try_parse() -> Result<Self, Error>

Parse from std::env::args_os(), return Err on error.
Source§

fn parse_from<I, T>(itr: I) -> Self
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, exit on error.
Source§

fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, return Err on error.
Source§

fn update_from<I, T>(&mut self, itr: I)
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, exit on error. Read more
Source§

fn try_update_from<I, T>(&mut self, itr: I) -> Result<(), Error>
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, return Err on error.

Auto Trait Implementations§

§

impl Freeze for Cli

§

impl RefUnwindSafe for Cli

§

impl Send for Cli

§

impl Sync for Cli

§

impl Unpin for Cli

§

impl UnsafeUnpin for Cli

§

impl UnwindSafe for Cli

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more