Skip to main content

Module http

Module http 

Source
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.