Expand description
HTTP request helpers built on ureq.
Every verb has a plain form and a _with_headers variant. Custom headers
are passed as a slice of (name, value) pairs, which keeps them ordered and
allows repeated header names. All requests send a User-Agent: agent-line
header and use a 5 second global timeout.
use agent_line::tools::{http_get_with_headers, http_post_json_with_headers};
// GET with a bearer token.
let body = http_get_with_headers(
"https://api.example.com/data",
&[("Authorization", "Bearer secret-token")],
)?;
// POST a JSON body alongside a custom header.
let payload = serde_json::json!({ "name": "agent-line" });
let reply = http_post_json_with_headers(
"https://api.example.com/items",
&payload,
&[("X-Request-Id", "abc-123")],
)?;Functionsยง
- http_
get - Send a GET request and return the response body as a string.
- http_
get_ with_ headers - Send a GET request with custom headers and return the response body as a string.
- http_
post - Send a POST request with a string body and return the response body.
- http_
post_ json - Send a POST request with a JSON body and return the response body.
- http_
post_ json_ with_ headers - Send a POST request with a JSON body, custom headers, and return the response body.
- http_
post_ with_ headers - Send a POST request with a body, custom headers, and return the response body.