httpclient

package
v0.0.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExitCodeForError

func ExitCodeForError(err error) int

ExitCodeForError maps an API error to a CLI exit code.

Types

type APIError

type APIError struct {
	StatusCode int
	Body       string
}

APIError represents an HTTP error response from an API.

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	BaseURL    string
	APIKey     string
	HeaderName string // Header name for API key (e.g. "Authorization", "X-API-KEY")
	HTTPClient *http.Client
}

func New

func New(baseURL, apiKey, headerName string) *Client

func (*Client) Delete

func (c *Client) Delete(path string, target interface{}) error

Delete performs a DELETE request.

func (*Client) Get

func (c *Client) Get(path string, target interface{}) error

Get performs a GET request and unmarshals the response into target.

func (*Client) Post

func (c *Client) Post(path string, body io.Reader, target interface{}) error

Post performs a POST request with a JSON body and unmarshals the response.

func (*Client) PostRaw

func (c *Client) PostRaw(path string, body io.Reader) ([]byte, int, error)

PostRaw performs a POST and returns the raw response body.

func (*Client) Put

func (c *Client) Put(path string, body io.Reader, target interface{}) error

Put performs a PUT request with a JSON body.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL