sdk-generator / rick-and-morty-sdk
Unofficial PHP SDK for the Rick and Morty API: characters, locations and episodes, with filters and pagination. Generated from a public Postman collection.
Package info
github.com/sdk-generator/rick-and-morty-sdk
pkg:composer/sdk-generator/rick-and-morty-sdk
Requires
- php: ^8.4
- sdk-generator/sdk-runtime: ^1.15.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
- dmorenof/rick-and-morty-sdk: v0.1.1
This package is auto-updated.
Last update: 2026-12-03 22:16:22 UTC
README
Characters, locations and episodes of the Rick and Morty API as typed PHP, no API key.
Every character, location and episode of the Rick and Morty API, one or several at a time, with its filters and pages. The API is free and needs no key.
Unofficial. Not affiliated with, endorsed by or supported by the Rick and Morty API, its authors or the owners of Rick and Morty. See NOTICE.md.
Why this SDK
- Generated from a Postman collection. The API publishes no OpenAPI document; the generator reads the community Postman collection and infers the models from its saved answers.
- Free API without a key: install and call.
- Checked against the live service. The SDK called the real API for every request of the collection; the one answer that did not fit (the last page, whose
nextisnull) led to a fix in the generator, and this version reads it. - One or several.
/character/2answers a character and/character/1,183a list; the SDK types the identifier as a list and the answer as either. - Generated from a public Postman collection, never edited by hand.
src/is produced by sdk-generator from the Postman collection 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. 8 operations and 33 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
ApiExceptionthat 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 oneConfigurationobject.
Install
PHP 8.4 or later.
composer require sdk-generator/rick-and-morty-sdk
Quick start
<?php use RickAndMortySDK\Character; use RickAndMortySDK\Configuration; use RickAndMortySDK\GetParams\Character as CharacterFilter; use RickAndMortySDK\PathParams\Character\ById; use RickAndMortySDK\RickAndMortyAPISDK; RickAndMortyAPISDK::configure(new Configuration()); $filter = new CharacterFilter(); $filter->name = 'rick'; $filter->status = 'alive'; $page = Character::get($filter); echo $page->info->count, " living Ricks\n"; foreach ($page->results as $character) { echo '- ', $character->name, ' (', $character->species, ")\n"; } $ids = new ById(); $ids->id = [1, 183]; echo json_encode(Character::getById($ids)), "\n"; // a character, or a list of them
The same example is in examples/quickstart.php. Every operation is listed in docs/OPERATIONS.md.
What it covers
8 operations. The biggest areas:
| Area | Operations |
|---|---|
character |
2 |
episode |
2 |
location |
2 |
/ |
1 |
graphql |
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 API is free and rate limited: cache what you can.
- A Postman collection shows examples, not a contract: fields are typed from the saved answers, and none is required.
- Version
0.1.0is a first release: the API of the SDK follows the source description, and a regenerated one can rename classes. Pin a version.
Documentation
- Operations catalog
- Vendor documentation
- sdk-runtime (what every SDK shares) and sdk-generator
- CHANGELOG.md, CONTRIBUTING.md, SECURITY.md
License
MIT, see LICENSE.md. The license covers this SDK's code, not the API, its trademarks or its terms: see NOTICE.md.