PHPackages                             nickbeen/rick-and-morty-api-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. nickbeen/rick-and-morty-api-php

ActiveLibrary[API Development](/categories/api)

nickbeen/rick-and-morty-api-php
===============================

The Rick And Morty API PHP Client

2.0.0(3y ago)121313MITPHPPHP ^8.1CI failing

Since Feb 20Pushed 1w ago1 watchersCompare

[ Source](https://github.com/nickbeen/rick-and-morty-api-php)[ Packagist](https://packagist.org/packages/nickbeen/rick-and-morty-api-php)[ Docs](https://github.com/nickbeen/rick-and-morty-api-php)[ RSS](/packages/nickbeen-rick-and-morty-api-php/feed)WikiDiscussions main Synced today

READMEChangelog (3)Dependencies (3)Versions (5)Used By (0)

The Rick and Morty API - PHP Client
===================================

[](#the-rick-and-morty-api---php-client)

[![Latest version](https://camo.githubusercontent.com/d36f32255adceccab7039753fca673682d516cf3da2e5e5d19dd496aad1f9691/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e69636b6265656e2f7269636b2d616e642d6d6f7274792d6170692d706870)](https://packagist.org/packages/nickbeen/rick-and-morty-api-php)[![Build status](https://camo.githubusercontent.com/8dcb44818b2ba98f839d6b627149db9443e4a1c1b4b9fd7d274f6bd47940c727/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e69636b6265656e2f7269636b2d616e642d6d6f7274792d6170692d7068702f72756e2d74657374732e796d6c)](https://packagist.org/packages/nickbeen/rick-and-morty-api-php)[![Total downloads](https://camo.githubusercontent.com/505c504dd47e61344da2a2cec136876d235aef978e99f8aed8417e6028e12a47/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e69636b6265656e2f7269636b2d616e642d6d6f7274792d6170692d706870)](https://packagist.org/packages/nickbeen/rick-and-morty-api-php)[![PHP Version](https://camo.githubusercontent.com/9fb9dc2888499cf03d9440faadd5c227a1b41492d364862c47cd1d42b3bbe399/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e69636b6265656e2f7269636b2d616e642d6d6f7274792d6170692d706870)](https://packagist.org/packages/nickbeen/rick-and-morty-api-php)[![License](https://camo.githubusercontent.com/588b89d6187318638a9e5eec3008b32e7f8ffc4f1a0eec0bf92fb162d2cc5bde/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e69636b6265656e2f7269636b2d616e642d6d6f7274792d6170692d706870)](https://packagist.org/packages/nickbeen/rick-and-morty-api-php)

An API wrapper written in PHP for the Rick and Morty API at .

Get all the information about characters, episodes and locations of Rick and Morty with this PHP client without messing around with Curl calls and JSON responses. This library does not return the same JSON provided by the API, but wraps everything in convenient PHP class objects. The Rick and Morty API is made by [Axel Fuhrmann](https://github.com/afuh).

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1

Installation
------------

[](#installation)

Install the library into your project with Composer.

```
composer require nickbeen/rick-and-morty-php-api --no-dev

```

Usage
-----

[](#usage)

Initiate a `Character`, `Episode` or `Location` model and use the available tools to list, retrieve or search within that model. The library returns a `NotFoundException` when using invalid arguments, retrieving nonexistent models or if the Rick and Morty API is not available. Implement a try block to handle the exception in your application in the best possible way.

### Collections

[](#collections)

Requests for all characters, episodes and locations as well as queries with search parameters will return a `Collection` object containing an array with results.

#### Collection object

[](#collection-object)

FieldTypeDescriptioninfo[Info](#info-object)Information about the collectionresults[Character\[\]](#characters)
[Episode\[\]](#episodes)
[Location\[\]](#locations)Array containing characters, episodes or locations#### Info object

[](#info-object)

FieldTypeDescriptioncountintegerThe length of the responsepagesintegerThe amount of pagesnext?stringLink to the next page (if it exists)prev?stringLink to the previous page (if it exists)**Usage**

For instructions for the usage of collections, check the sections [Characters](#characters), [Episodes](#episodes) and [Locations](#locations) for more details and examples.

### Api

[](#api)

This library contains a useful method to return all the endpoints of the Rick and Morty API in an `Api` object.

#### Api object

[](#api-object)

FieldTypeDescriptioncharactersstringEndpoint used for retrieving charactersepisodesstringEndpoint used for retrieving episodeslocationsstringEndpoint used for retrieving locations**Usage**

Retrieve an `Api` object containing the endpoints for retrieving characters, episodes and locations.

```
$api = new Api();
$api->get();

echo $api->characters;
echo $api->episodes;
echo $api->locations;
```

### Characters

[](#characters)

Retrieve any character from Rick and Morty, browse through all the characters or use search parameters to find a specific character.

#### Character object

[](#character-object)

FieldTypeDescriptionidintegerThe id of the characternamestringThe name of the characterstatusstringThe status of the characterspeciesstringThe species of the charactertypestringThe type or subspecies of the charactergenderstringThe gender of the characterorigin[Origin](#origin-object)Name and link to the character's origin location endpointlocation[Location](#location-object)Name and link to the character's last known location endpointimagestringLink to the character's imageepisodestring\[\]List of episodes in which this character appearedurlstringLink to the character's own URL endpointcreatedstringTime at which the character was created in the database#### Origin object

[](#origin-object)

FieldTypeDescriptionnamestringThe name of the characterurlstringUrl to the character's last known location endpoint#### Location object

[](#location-object)

FieldTypeDescriptionnamestringThe name of the character's origin locationurlstringUrl to the character's origin location endpoint#### List characters

[](#list-characters)

Retrieve a `Collection` object with next 20 characters from the first page.

```
$characters = new Character();
$characters->get();

foreach ($characters->results as $character) {
    echo $character->name;
}
```

Retrieve a `Collection` object with next 20 characters from the second page.

```
$characters = new Character();
$characters->page(2)
    ->get();

foreach ($characters->results as $character) {
    echo $character->name;
}
```

#### Get character

[](#get-character)

Retrieve a `Character` object with id 1.

```
$character = new Character();
$character->get(1);

echo $character->name;
```

#### Get multiple characters

[](#get-multiple-characters)

Retrieve an array containing `Character` objects with id 1 and 2.

```
$characters = new Character();
$characters->get(1,2);

foreach ($characters as $character) {
    echo $character->name;
}
```

#### Search characters

[](#search-characters)

It is possible to search for characters based on search parameters such as species and name. For gender and status you can use a Gender enum object and Status enum object for auto-completion in an IDE.

MethodTypeDescriptionwithGender[Gender](#gender-object)Filter by given genderwithNamestringFilter by given namewithSpeciesstringFilter by given specieswithStatus[Status](#status-object)Filter by given statuswithTypestringFilter by given type#### Gender object

[](#gender-object)

FieldTypeDescriptionGender::FemalestringFemaleGender::GenderlessstringGenderlessGender::MalestringMaleGender::UnknownstringUnknown#### Status object

[](#status-object)

FieldTypeDescriptionStatus::AlivestringAliveStatus::DeadstringDeadStatus::UnknownstringUnknownRetrieve a `Collection` with all alive male Ricks.

```
$characters = new Character();
$characters->withGender(Gender::Male)
    ->withName('Rick')
    ->withStatus(Status::Alive)
    ->get();

foreach ($characters->results as $character) {
    echo $character->name;
}
```

### Episodes

[](#episodes)

Retrieve any episode from Rick and Morty, browse through all the episodes or use search parameters to find a specific episode.

#### Episode object

[](#episode-object)

FieldTypeDescriptionidintegerThe id of the episodenamestringThe name of the episodeair\_datestringThe air date of the episodeepisodestringThe code of the episodecharactersstring\[\]List of characters who have been seen in the episodeurlstringLink to the episode's own URL endpointcreatedstringTime at which the episode was created in the database#### List episodes

[](#list-episodes)

Retrieve a `Collection` object with first 20 episodes from the first page.

```
$episodes = new Episode();
$episodes->get();

foreach ($episodes->results as $episode) {
    echo $episode->name;
}
```

Retrieve a `Collection` object with next 20 episodes from the second page.

```
$episode = new Episode();
$episode->page(2)
    ->get();

foreach ($episodes->results as $episode) {
    echo $episode->name;
}
```

#### Get episode

[](#get-episode)

Retrieve an `Episode` object with id 1.

```
$episode = new Episode();
$episode->get(1);

echo $episode->name;
```

#### Get multiple episodes

[](#get-multiple-episodes)

Retrieve an array containing `Episode` objects with id 1 and 2.

```
$episodes = new Episode();
$episodes->get(1,2);

foreach ($episodes as $episode) {
    echo $episode->name;
}
```

#### Search episodes

[](#search-episodes)

It is possible to search for episodes based on search parameters such as episode code (e.g. S01E01) and name.

MethodTypeDescriptionwithEpisodestringFilter by given episode codewithNamestringFilter by given nameRetrieve a `Collection` object with all episodes from season 1.

```
$episodes = new Episode();
$episodes->withEpisode('S01')
    ->get();

foreach ($episodes->results as $episode) {
    echo $episode->name;
}
```

### Locations

[](#locations)

Retrieve any location from Rick and Morty, browse through all the featured locations or use search parameters to find a specific location.

**Location object**

FieldTypeDescriptionidintegerThe id of the locationnamestringThe name of the locationtypestringThe type of the episodedimensionstringThe dimension in which the location is locatedresidentsstring\[\]List of characters who have been seen in the locationurlstringLink to the location's own URL endpointcreatedstringTime at which the location was created in the database#### List locations

[](#list-locations)

Retrieve a `Collection` object with first 20 locations from the first page.

```
$locations = new Location();
$locations->get();

foreach ($locations->results as $location) {
    echo $location->name;
}
```

Retrieve a `Collection` object with next 20 locations from the second page.

```
$locations = new Location();
$locations->page(2)
    ->get();

foreach ($locations->results as $location) {
    echo $location->name;
}
```

#### Get location

[](#get-location)

Retrieve a `Location` object with id 1.

```
$location = new Location();
$location->get(1);

echo $location->name;
```

#### Get multiple locations

[](#get-multiple-locations)

Retrieve an array containing `Location` objects with id 1 and 2.

```
$locations = new Location();
$locations->get(1,2);

foreach ($locations as $location) {
    echo $location->name;
}
```

#### Search locations

[](#search-locations)

It is possible to search for locations based on search parameters such as dimension and name.

MethodTypeDescriptionwithDimensionstringFilter by given dimensionwithNamestringFilter by given namewithTypestringFilter by the given typeRetrieve a `Collection` object with all locations within dimension C-137.

```
$location = new Location();
$location->withDimension('Dimension C-137')
    ->get();

foreach ($locations->results as $location) {
    echo $location->name;
}
```

FAQ
---

[](#faq)

### What are the limits of the API?

[](#what-are-the-limits-of-the-api)

The API is open and requires no authentication. According to the R implementation [Mortyr](https://github.com/MikeJohnPage/mortyr), the API allows 10.000 requests per IP address per day after which any request will result in a 429 (Too Many Requests) response.

### Can I get more than 20 results per page in a Collection?

[](#can-i-get-more-than-20-results-per-page-in-a-collection)

The API returns 20 results per page by design and this cannot be adjusted. It is however possible to return more than 20 results by manually inserting more than 20 ids in the `get()` method.

### How about extra filters?

[](#how-about-extra-filters)

Not possible, this library already offers all the available filters currently provided by the API.

### Why is the code of the episode called `episode` in the Episode model?

[](#why-is-the-code-of-the-episode-called-episode-in-the-episode-model)

It looks like an oopsie from the creator of the Rick And Morty API. There is an unresolved [pull request](https://github.com/afuh/rick-and-morty-api/issues/94) to rename the field to `code`.

License
-------

[](#license)

This library is licensed under the MIT License (MIT). See the [LICENSE](LICENSE.md) for more details.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance64

Regular maintenance activity

Popularity19

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 77.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~143 days

Total

4

Last Release

1164d ago

Major Versions

1.x-dev → 2.0.02023-04-25

PHP version history (2 changes)1.0.0PHP ^8.0

2.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/66799549?v=4)[Nick Been](/maintainers/nickbeen)[@nickbeen](https://github.com/nickbeen)

---

Top Contributors

[![nickbeen](https://avatars.githubusercontent.com/u/66799549?v=4)](https://github.com/nickbeen "nickbeen (21 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![winchester7](https://avatars.githubusercontent.com/u/5810446?v=4)](https://github.com/winchester7 "winchester7 (1 commits)")

---

Tags

apiphprick-and-mortyphpapirick and morty

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nickbeen-rick-and-morty-api-php/health.svg)

```
[![Health](https://phpackages.com/badges/nickbeen-rick-and-morty-api-php/health.svg)](https://phpackages.com/packages/nickbeen-rick-and-morty-api-php)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k9.5M88](/packages/openai-php-laravel)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.7k409.0k6](/packages/theodo-group-llphant)[hubspot/api-client

Hubspot API client

24016.2M20](/packages/hubspot-api-client)[resend/resend-php

Resend PHP library.

617.2M42](/packages/resend-resend-php)[checkout/checkout-sdk-php

Checkout.com SDK for PHP

563.6M13](/packages/checkout-checkout-sdk-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
