mealdb

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: 11 Imported by: 0

Documentation

Overview

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

The free v1 API uses the static key "1" baked into the base URL path (https://www.themealdb.com/api/json/v1/1). No login, no OAuth. 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 = "themealdb.com"

Host is the site this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Area

type Area struct {
	Rank int    `json:"rank"`
	Name string `json:"name"`
}

Area is one cuisine area/origin from TheMealDB.

type Category

type Category struct {
	Rank        int    `json:"rank"`
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

Category is one meal category from TheMealDB.

type Client

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

Client talks to TheMealDB over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Areas

func (c *Client) Areas(ctx context.Context) ([]Area, error)

Areas returns all cuisine areas/origins. Calls GET /list.php?a=list.

func (*Client) Categories

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

Categories returns all meal categories. Calls GET /categories.php.

func (*Client) Filter

func (c *Client) Filter(ctx context.Context, opts FilterOptions) ([]FilterResult, error)

Filter returns summary meal records matching the given filter options. At least one of Category or Area must be set.

func (*Client) Get

func (c *Client) Get(ctx context.Context, id string) (Meal, error)

Get returns a meal by ID. Returns an error if the ID is not found. Calls GET /lookup.php?i={id}.

func (*Client) Random

func (c *Client) Random(ctx context.Context) (Meal, error)

Random returns one random meal from the API. Calls GET /random.php.

func (*Client) Search

func (c *Client) Search(ctx context.Context, name string, limit int) ([]Meal, error)

Search searches meals by name. Returns all matches; trims to limit if > 0. Calls GET /search.php?s={encoded_name}.

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 for the free v1 API.

type Domain

type Domain struct{}

Domain is the mealdb 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 FilterOptions

type FilterOptions struct {
	Category string // e.g. "Seafood", "Chicken"
	Area     string // e.g. "Japanese", "Italian"
	Limit    int
}

FilterOptions controls which filter is applied.

type FilterResult

type FilterResult struct {
	Rank      int    `json:"rank"`
	ID        string `json:"id"`
	Name      string `json:"name"`
	Thumbnail string `json:"thumbnail"`
}

FilterResult is a summary meal returned by the filter endpoint. It does not include ingredients; use Get to fetch full details.

type Ingredient

type Ingredient struct {
	Name    string `json:"name"`
	Measure string `json:"measure"`
}

Ingredient is one meal ingredient with its measure.

type Meal

type Meal struct {
	Rank         int          `json:"rank"`
	ID           string       `json:"id"`
	Name         string       `json:"name"`
	Category     string       `json:"category"`
	Area         string       `json:"area"` // cuisine origin
	Instructions string       `json:"instructions"`
	Thumbnail    string       `json:"thumbnail"`
	YouTube      string       `json:"youtube"`
	Ingredients  []Ingredient `json:"ingredients"`
}

Meal is one recipe from TheMealDB.

Jump to

Keyboard shortcuts

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