Skip to main content

request_json

Function request_json 

Source
pub async fn request_json(
    client: &Client,
    base_url: &str,
    token: Option<&str>,
    action: &str,
    method: Method,
    path: &str,
    query: Option<&[(&str, String)]>,
    body: Option<&Value>,
) -> Result<Value>
Expand description

Issues one request against base_url using the caller-supplied client, and maps the transport/status outcome into a Result.

token, when Some, is sent as the X-Gotify-Key header — None for the two unauthenticated endpoints (health, version). action is a friendly name (e.g. "send_message") used only for the tracing span/logs this wraps the request in — every GotifyClient method funnels through this one function, so this is the one place instrumentation needs to live for it to cover all of them consistently.

§Errors

Returns GotifyError::Timeout / GotifyError::Connect / GotifyError::Request for transport failures, GotifyError::Unauthorized / GotifyError::NotFound / GotifyError::RateLimited for the status codes Gotify uses for those conditions, and GotifyError::UnexpectedStatus for any other non-success status (its body is JSON when the response was JSON, otherwise the raw text). A 204 No Content (used by Gotify’s delete endpoints) returns a synthetic {"status": "ok"}. Otherwise returns GotifyError::Decode if the body isn’t valid JSON.