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 ¶
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 (*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).
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) 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.
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.