rickmorty

package
v0.1.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 rickmorty is the library behind the rickmorty command line: the HTTP client, request shaping, and the typed data models for the Rick and Morty API at rickandmortyapi.com.

The API is completely open — no authentication or API key required. The Client sets a polite User-Agent, paces requests, and retries transient 429 and 5xx failures with exponential backoff.

Index

Constants

View Source
const (
	// Host is the site this client talks to.
	Host = "rickandmortyapi.com"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Character

type Character struct {
	Rank     int    `json:"rank"`
	ID       int    `json:"id"`
	Name     string `json:"name"`
	Status   string `json:"status"` // "Alive", "Dead", "unknown"
	Species  string `json:"species"`
	Gender   string `json:"gender"`
	Origin   string `json:"origin"`   // origin.name
	Location string `json:"location"` // location.name
	Episodes int    `json:"episodes"` // len(episode array)
	URL      string `json:"url"`      // rickandmortyapi.com/api/character/{id}
}

Character is one entry from the Rick and Morty character list.

type Client

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

Client talks to the Rick and Morty API over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Characters

func (c *Client) Characters(ctx context.Context, name string, status string, limit int) ([]Character, error)

Characters fetches page 1 of the character list with optional name and status filters. Pass limit <= 0 for all results from page 1 (up to 20).

func (*Client) Episodes

func (c *Client) Episodes(ctx context.Context, limit int) ([]Episode, error)

Episodes fetches page 1 of the episode list. Pass limit <= 0 for all results from page 1 (up to 20).

func (*Client) Locations

func (c *Client) Locations(ctx context.Context, limit int) ([]Location, error)

Locations fetches page 1 of the location list. Pass limit <= 0 for all results from page 1 (up to 20).

type Config

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

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Domain

type Domain struct{}

Domain is the rickmorty 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 Episode

type Episode struct {
	Rank       int    `json:"rank"`
	ID         int    `json:"id"`
	Name       string `json:"name"`
	AirDate    string `json:"air_date"`
	Episode    string `json:"episode"`    // e.g. "S01E01"
	Characters int    `json:"characters"` // count of character URLs
	URL        string `json:"url"`
}

Episode is one entry from the Rick and Morty episode list.

type Location

type Location struct {
	Rank      int    `json:"rank"`
	ID        int    `json:"id"`
	Name      string `json:"name"`
	Type      string `json:"type"`      // e.g. "Planet", "Space station"
	Dimension string `json:"dimension"` // e.g. "Dimension C-137"
	Residents int    `json:"residents"` // count
	URL       string `json:"url"`
}

Location is one entry from the Rick and Morty location list.

Jump to

Keyboard shortcuts

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