catapi

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package catapi is the library behind the catapi command line: the HTTP client, request shaping, and typed data models for TheCatAPI.

The free tier at api.thecatapi.com requires no API key. The Client sets a polite User-Agent, paces requests, and retries transient failures (429 and 5xx) with a capped backoff.

Index

Constants

View Source
const Host = "api.thecatapi.com"

Host is the site this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Breed added in v0.2.0

type Breed struct {
	ID          string `kit:"id" json:"id"`
	Name        string `json:"name"`
	Origin      string `json:"origin"`
	Temperament string `json:"temperament"`
	LifeSpan    string `json:"life_span"`
	Description string `json:"description"`
}

Breed is one cat breed from TheCatAPI.

type Category added in v0.2.0

type Category struct {
	ID   int    `kit:"id" json:"id"`
	Name string `json:"name"`
}

Category is one image category from TheCatAPI.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to TheCatAPI over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Breeds added in v0.2.0

func (c *Client) Breeds(ctx context.Context, limit, page int) ([]Breed, error)

Breeds returns all cat breeds paginated. limit and page are passed directly to the API. Calls GET /v1/breeds.

func (*Client) Categories added in v0.2.0

func (c *Client) Categories(ctx context.Context) ([]Category, error)

Categories returns all image categories. Calls GET /v1/categories.

func (*Client) Search added in v0.2.0

func (c *Client) Search(ctx context.Context, limit int, breed string, hasBreeds bool) ([]Image, error)

Search returns cat images. Use breed to filter by breed ID (e.g. "beng"). Set hasBreeds to true to only return images that have breed info attached. limit controls the maximum number of results (default 5 if <= 0). Calls GET /v1/images/search.

func (*Client) SearchBreeds added in v0.2.0

func (c *Client) SearchBreeds(ctx context.Context, query string) ([]Breed, error)

SearchBreeds searches breeds by name query. Calls GET /v1/breeds/search.

type Config added in v0.2.0

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds all tunable parameters for the Client.

func DefaultConfig added in v0.2.0

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults for the free API tier.

type Domain

type Domain struct{}

Domain is the catapi driver.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns an input into the canonical (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Image added in v0.2.0

type Image struct {
	ID     string `kit:"id" json:"id"`
	URL    string `json:"url"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
	Breed  string `json:"breed"`  // first breed name, or ""
	Origin string `json:"origin"` // first breed origin, or ""
}

Image is one cat image result from TheCatAPI.

Jump to

Keyboard shortcuts

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