Expand description
Shared HTTP helpers for the platform clients (pr, issue,
release, pipeline, package).
Before 0.7.14, each surface had its own boilerplate around reqwest:
build a client, set user-agent, send, parse status, extract a JSON
message field for errors. That repeated across ~15 client structs
(GitHub × GitLab × Gitea × 5 surfaces).
This module consolidates that into three primitives:
make_client— builds thereqwest::blocking::Clientwith the gitorii user-agent. Use everywhere instead of inlineClient::builder().send_json— runs aRequestBuilder, checks status, returns the parsed JSON body. Folds the three-line send/status/parse dance into one call.send_empty— same, but for operations that don’t return a body we care about (cancel, retry, delete).extract_array— turns a JSON value into a&Vec<Value>with a consistent error message when the platform returns a non-array.
The ctx parameter on send_json / send_empty is a free-form
label that goes into the error message (e.g. "GitHub",
"Gitea (cancel pipeline)"). Callers include the URL there when it
helps debugging.
Constants§
- USER_
AGENT - User-agent string sent on every platform API call.
Functions§
- extract_
array - Extract the top-level array from a JSON value, or fail with a consistent diagnostic that includes the URL/context.
- make_
client - Construct the standard blocking HTTP client used by every platform
client. Sets a global request timeout so a hung API can’t freeze
torii forever. Panics only on a build failure we don’t expect at
runtime (would mean
reqwestis fundamentally broken). - send_
bytes - Send a request and return its body as raw bytes. For artifact downloads (zip / tarball) — the bytes go straight to disk on the caller’s side.
- send_
empty - Send a request and ignore the response body, only checking status. Used for cancel / retry / delete style operations.
- send_
json - Send a request, check status, parse JSON. Returns the parsed value
on 2xx; on any other status, returns a
PlatformApierror including the platform’s own message field when present. - send_
text - Send a request and return its body as text. For endpoints like
/jobs/{id}/traceor/builds/{id}/logthat return plain text instead of JSON — bypassessend_json’sserde_jsonparse step.