PHPackages                             zmaglica/rick-and-morty-api-wrapper - 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. zmaglica/rick-and-morty-api-wrapper

ActiveLibrary[API Development](/categories/api)

zmaglica/rick-and-morty-api-wrapper
===================================

Wrapper for The Rick and Morty API with query builder

v1.0.2(6y ago)018MITPHPPHP ^7.0CI failing

Since Oct 14Pushed 6y agoCompare

[ Source](https://github.com/zmaglica/rick-and-morty-api-wrapper)[ Packagist](https://packagist.org/packages/zmaglica/rick-and-morty-api-wrapper)[ Docs](https://github.com/zmaglica/rick-and-morty-api-wrapper)[ RSS](/packages/zmaglica-rick-and-morty-api-wrapper/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (3)Versions (7)Used By (0)

The Rick and Morty API wrapper with query builder
=================================================

[](#the-rick-and-morty-api-wrapper-with-query-builder)

[![Latest Version on Packagist](https://camo.githubusercontent.com/79099767417d16609be844750731904e6d73553fec65c8b37cd48cdaf7d2646e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a6d61676c6963612f7269636b2d616e642d6d6f7274792d6170692d777261707065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/zmaglica/rick-and-morty-api-wrapper)[![Build Status](https://camo.githubusercontent.com/973a2f935d4eb2985aab667935ac13b65af19aeae3e2b5f23fa6a223f67ec0fa/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7a6d61676c6963612f7269636b2d616e642d6d6f7274792d6170692d777261707065722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/zmaglica/rick-and-morty-api-wrapper)[![Quality Score](https://camo.githubusercontent.com/84cd512d71a0e910f573b8f822038391b4365007c635901f314ea4f621ae9182/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7a6d61676c6963612f7269636b2d616e642d6d6f7274792d6170692d777261707065722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/zmaglica/rick-and-morty-api-wrapper)[![Total Downloads](https://camo.githubusercontent.com/ae6a9ad54c071ce68779026ff3e708b7b47395c4e2da4ba9bc7015c0801916b7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a6d61676c6963612f7269636b2d616e642d6d6f7274792d6170692d777261707065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/zmaglica/rick-and-morty-api-wrapper)

This PHP package is wrapper for  with query builder that is similar to Doctrine and Laravel database query builder. It contains popular function like where clauses, easy pagination, eager loading of results and many other things.

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

[](#installation)

You can install the package via composer:

```
composer require zmaglica/rick-and-morty-api-wrapper
```

Usage
-----

[](#usage)

Default query function that can be use on all API endpoints

```
where() // Add custom filtering. where(['name' => 'Rick'])
clear() // Clear all filters (where clauses)
whereId() // Add character, location or episode ID to where clause whereId([1,2,3])
setPage() // Specify request page. Example: setPage(2)
nextPage() // Set next page
previousPage() // Set previous page
raw() // Execute raw URI to the Rick and Morty API without any filters and pages
```

Default functions that can be used **AFTER** request is performed

```
toArray() // Get results as array
toJson() // Get results as json
isFirstPage() // Check if request result page is first page
isLastPage() //Check if request result page is last page
count() // Get total number of records
pages() // Get total number of pages
prev() // Send request to fetch data from previous page
next() // Send request to fetch data from next page
first() // Send request to fetch data from first page
goToPage(int $page) // Send request to fetch data from desired page
last() // Send request to fetch data from last page
```

Create instance of API wrapper like this

```
$api = new RickAndMortyApiWrapper()
```

You can set up your own GuzzleHTTP client by calling `setClient()` method . Also you can pass array to class constructor to add custom Guzzle HTTP configuration options

##### Character

[](#character)

Character API documentation can be found here:

First, create instance of API wrapper

```
$api = new RickAndMortyApiWrapper()
```

After that call method `character()` where you can execute API calls for character schema

```
$characterApi = $api->character(); // Or you can directly call new RickAndMortyApiWrapper()->character()
```

After that you can execute The Rick and Morty API calls.

##### Examples:

[](#examples)

Get all characters

```
$characterApi->all();
```

Get single character

```
$characterApi->get(1);
```

Get multiple characters

```
$characterApi->get([1,2,3]);
```

Get character origin location

```
$characterApi->getOrigin(1);
```

Get character last known location

```
$characterApi->getLocation(1);
```

Add "Status" filter to request

```
$characterApi->isAlive() // fetch alive characters
$characterApi->isDead() // fetch dead characters
$characterApi->isStatusUnknown() // fetch characters with unknown status
```

Add "Gender" filter to request

```
$characterApi->isFemale() // fetch female characters
$characterApi->isMale() // fetch male characters
$characterApi->isGenderless() // fetch genderless characters
$characterApi->isGenderUnknown() // fetch unknown gender characters
```

Run custom query parameter using built-in where functionality

```
$characterApi->where(['status' => 'alive', 'gender' => 'female']) //Get all female characters that are alive.
```

Same query can be achieved by using this:

```
$characterApi->isAlive()->isFemale()
```

Custom filtering can be achieved by using available filter with where clause (whereFilterName)

```
$characterApi->whereName('Rick') // filter by the given name.
$characterApi->whereStatus('alive') //  filter by the given status (alive, dead or unknown).
$characterApi->whereType('Korblock') //   filter by the given type.
$characterApi->whereGender('female') // filter by the given gender (female, male, genderless or unknown).
```

**After** you execute API call you can fetch location and episodes from founded characters using these methods:

```
$characterApi->all()->locations() // Get instace of Location API from founded characters. Pass false to constructor if you want to remove duplicates
$characterApi->all()->getLocations() // Get all location from founded characters. Pass false to constructor if you want to remove duplicates
$characterApi->all()->origins() // Get instace of origin Location API from founded characters. Pass false to constructor if you want to remove duplicates
$characterApi->all()->getOrigins() // Get all origin location from founded characters. Pass false to constructor if you want to remove duplicates
$characterApi->all()->episodes() // Get instace of Episode API from founded characters. Pass false to constructor if you want to remove duplicates
$characterApi->all()->getEpisodes() // Get all episode from founded characters. Pass false to constructor if you want to remove duplicates
```

Here is the example of getting all episodes of female characters that are alive.

```
$characterApi->isAlive()->isFemale->get()->getEpisodes();
// Same thing can be achieved by using following code
$characterApi->whereStatus('alive')->whereGender('female')->get()->getEpisodes();
// and using this code
$characterApi->where(['status' => 'alive', 'gender' => 'female'])->get()->getEpisodes();
```

### Todo

[](#todo)

- Add more examples and update documentation for Location and Episode API

### Testing

[](#testing)

```
vendor/bin/phpunit
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Zvonimir Maglica](https://github.com/zmaglica)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

PHP Package Boilerplate
-----------------------

[](#php-package-boilerplate)

This package was generated using the [PHP Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

6

Last Release

2449d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c11365e684e343c5f211efe3a16f3f989f988dd926cd19a1a1ef9e175b85fc62?d=identicon)[zmaglica](/maintainers/zmaglica)

---

Top Contributors

[![zmaglica](https://avatars.githubusercontent.com/u/15913573?v=4)](https://github.com/zmaglica "zmaglica (10 commits)")

---

Tags

zmaglicarick-and-morty-api-wrapper

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3661.2M46](/packages/tencentcloud-tencentcloud-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k496.1k34](/packages/neuron-core-neuron-ai)[avalara/avataxclient

Client library for Avalara's AvaTax suite of business tax calculation and processing services. Uses the REST v2 API.

528.3M7](/packages/avalara-avataxclient)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

252.5k](/packages/eslazarev-wildberries-sdk)[files.com/files-php-sdk

Files.com PHP SDK

2478.1k](/packages/filescom-files-php-sdk)[aimeos/prisma

A powerful PHP package for integrating media related Large Language Models (LLMs) into your applications

1942.4k4](/packages/aimeos-prisma)

PHPackages © 2026

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