Documentation
¶
Overview ¶
Package swapi is the library behind the swapi command line: the HTTP client, request shaping, and typed data models for the Star Wars API.
The Client sets a real User-Agent, paces requests, and retries the transient failures (429 and 5xx) that any public API throws under load. All six resource types are supported: people, films, planets, starships, vehicles, and species.
Index ¶
- Constants
- type Client
- func (c *Client) Films(ctx context.Context) ([]Film, error)
- func (c *Client) People(ctx context.Context, search string, limit int) ([]Person, error)
- func (c *Client) Planets(ctx context.Context, search string, limit int) ([]Planet, error)
- func (c *Client) Species(ctx context.Context, search string, limit int) ([]Species, error)
- func (c *Client) Starships(ctx context.Context, search string, limit int) ([]Starship, error)
- func (c *Client) Vehicles(ctx context.Context, search string, limit int) ([]Vehicle, error)
- type Config
- type Domain
- type Film
- type Person
- type Planet
- type Species
- type Starship
- type Vehicle
Constants ¶
const BaseURL = "https://" + Host
BaseURL is the root every request is built from.
const Host = "swapi.py4e.com"
Host is the site this client talks to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the Star Wars API over HTTP.
func (*Client) People ¶
People returns Star Wars characters. search is optional ("" means all). Follows pagination until limit is satisfied or no more pages remain.
func (*Client) Species ¶
Species returns species/races from the Star Wars universe. search is optional.
type Config ¶
type Config struct {
BaseURL string
UserAgent string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds tunable knobs for the HTTP client.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns sensible defaults for production use.
type Domain ¶
type Domain struct{}
Domain is the swapi kit driver. It carries no state; the per-run client is built by the factory Register hands to kit.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, hostnames, and the identity used in help and version.
type Film ¶
type Film struct {
Title string `json:"title"`
EpisodeID int `json:"episode_id"`
Director string `json:"director"`
Producer string `json:"producer"`
ReleaseDate string `json:"release_date"`
URL string `json:"url"`
}
Film is one of the 7 canonical Star Wars films.
type Person ¶
type Person struct {
Name string `json:"name"`
Height string `json:"height"`
Mass string `json:"mass"`
HairColor string `json:"hair_color"`
BirthYear string `json:"birth_year"`
Gender string `json:"gender"`
URL string `json:"url"`
}
Person is a character from the Star Wars films.
type Planet ¶
type Planet struct {
Name string `json:"name"`
Climate string `json:"climate"`
Terrain string `json:"terrain"`
Population string `json:"population"`
URL string `json:"url"`
}
Planet is a planet in the Star Wars universe.
type Species ¶
type Species struct {
Name string `json:"name"`
Classification string `json:"classification"`
Language string `json:"language"`
AverageLifespan string `json:"average_lifespan"`
URL string `json:"url"`
}
Species is a species or race in the Star Wars universe.
type Starship ¶
type Starship struct {
Name string `json:"name"`
Model string `json:"model"`
Manufacturer string `json:"manufacturer"`
StarshipClass string `json:"starship_class"`
HyperdriveRating string `json:"hyperdrive_rating"`
URL string `json:"url"`
}
Starship is a starship used in the Star Wars films.