Search by

sdk-generator / themealdb-sdk

dmorenof

Unofficial PHP SDK for TheMealDB: search meals, look them up, random meals, categories and filters. Generated from a recorded browser session (HAR).

Package info

github.com/sdk-generator/themealdb-sdk

pkg:composer/sdk-generator/themealdb-sdk

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.1 2026-12-03 20:15 UTC

This package is auto-updated.

Last update: 2026-12-03 22:17:05 UTC


README

License: MIT PHP 8.4+ PHPStan level max Packagist

Recipes from TheMealDB as typed PHP, generated from a recorded browser session.

Search meals by name or first letter, look one up, get a random one, list categories, areas and ingredients, and filter by them, from TheMealDB and its free test key.

Unofficial. Not affiliated with, endorsed by or supported by TheMealDB. See NOTICE.md.

Why this SDK

  • Generated from real traffic. TheMealDB publishes no machine-readable description; the generator read an HTTP Archive of real calls and inferred the operations, parameters and models from it.
  • Free test key built into the address: install and call.
  • Typed answers. A meal is a Meal model, a search a list of them.
  • Generated from a recorded browser session (HAR), never edited by hand. src/ is produced by sdk-generator from the HTTP Archive (HAR) of real calls described in contract/SOURCE.md, on top of the shared sdk-runtime: when the source changes you regenerate, you do not patch.
  • Typed end to end. 6 operations and 11 typed request, answer and model classes. A request is a model whose fields are checked where you assign them (PHP 8.4 property hooks); an answer is a model; a list is a typed collection. PHPStan at the maximum level reports no error on the whole SDK.
  • One way to fail. An HTTP answer the contract does not declare as success is an ApiException that keeps the raw response and, when the API documents it, the decoded error as a model. Network failures keep their own type.
  • Production controls included. PSR-18 HTTP client (Guzzle by default), timeouts (30 s / 10 s by default), retries with Retry-After, redirect policy, middleware and per-environment servers, all in one Configuration object.

Install

PHP 8.4 or later.

composer require sdk-generator/themealdb-sdk

Quick start

<?php
use TheMealDbSDK\Configuration;
use TheMealDbSDK\GetParams\Search as SearchParams;
use TheMealDbSDK\Search;
use TheMealDbSDK\ThemealdbComSDK;

ThemealdbComSDK::configure(new Configuration());

$params = new SearchParams();
$params->s = 'Arrabiata';
$result = Search::get($params);
foreach ($result->meals ?? [] as $meal) {
    echo $meal->strMeal, ' (', $meal->strCategory, ")\n";
}

The same example is in examples/quickstart.php. Every operation is listed in docs/OPERATIONS.md.

What it covers

6 operations. The biggest areas:

Area Operations
categories.php 1
filter.php 1
list.php 1
lookup.php 1
random.php 1
search.php 1

Handling errors

use Dmorenof\SdkRuntime\ApiException;

try {
    // ... any call from the quick start
} catch (ApiException $e) {
    echo $e->response->status, "\n";   // the HTTP status
    echo $e->response->body, "\n";     // the raw body, always kept
    var_dump($e->error);                // the decoded error model, when the API documents one
}

Configuration

Configuration is the only place to set anything: baseUrl, securityCredentials, headers, timeout, connectTimeout, retryPolicy, redirectPolicy, middleware, httpClient (any PSR-18 client), serverVariables. Use Client::connect($configuration) instead of the static facades when you need several independent connections.

Good to know

  • The address includes TheMealDB's public test key 1 (/api/json/v1/1), meant for development. For production, TheMealDB asks supporters for a key: set $configuration->baseUrl to the address with yours.
  • Generated from what the capture shows: an endpoint or field not used in it is not in the SDK, and no field is required.
  • Version 0.1.0 is a first release: the API of the SDK follows the source description, and a regenerated one can rename classes. Pin a version.

Documentation

License

MIT, see LICENSE.md. The license covers this SDK's code, not the API, its trademarks or its terms: see NOTICE.md.