Documentation
¶
Overview ¶
Package client is a thin, strict HTTP client for the New API admin surface.
It exists instead of a generated OpenAPI client because the admin API is not fully described by any spec: the two behaviours that break naive clients are handled here explicitly.
- New API answers a failed call with HTTP 200 and {"success": false}. Checking the status code alone reports success on every rejection.
- The admin surface needs both an Authorization bearer token and a New-Api-User header carrying the numeric user id.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("not found (404)") ErrUnauth = errors.New("unauthorized (401/403): the access token is invalid, expired, or missing a scope") ErrRateLimit = errors.New("rate limited (429)") ErrUpstream = errors.New("upstream error (5xx)") ErrBadRequest = errors.New("bad request (400)") )
Sentinel errors surfaced to the agent so it can react without parsing prose.
var ErrReadOnly = errors.New("server is in read-only mode: NEWAPI_READ_ONLY=true")
ErrReadOnly is returned for a mutating call while the server is in read-only mode.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to one New API instance.
func NewWithOptions ¶
NewWithOptions builds a client from explicit options.
type Envelope ¶
type Envelope struct {
Success bool `json:"success"`
Message string `json:"message"`
Data json.RawMessage `json:"data"`
}
Envelope is New API's universal JSON response wrapper.
type Response ¶
type Response struct {
StatusCode int
Body []byte
// Envelope is non-nil when the body parsed as New API's wrapper.
Envelope *Envelope
}
Response is one completed upstream call.
func (*Response) Data ¶
func (r *Response) Data() json.RawMessage
Data returns the envelope's data payload, or the raw body when there is no envelope.