The Rick and Morty API JavaScript client
Hey, did you ever want to hold a terry fold?,
I got one right here, grab my terry flap.
This is a Node wrapper to use the The Rick and Morty API in your favourite JavaScript project.
To get started check the documentation on rickandmortyapi.com
Installation
npm i rickmortyapi
or
yarn add rickmortyapi
Usage
import { getCharacter } from 'rickmortyapi'
import shlaami from 'rickmortyapi'
const tinyRick = require('rickmortyapi')
All methods return a promise.
getCharacter()
getEpisode()
getLocation()
All the methods work in the same way. The only exception is the queries that you can pass as ab object to each method.
To know more about the schema of each response, please check here
Get by ID
const rick = await getCharacter(1)
const earth = await getLocation(1)
const episodeOne = await getEpisode(1)
const theSmiths = await getCharacter([ 2, 3, 4, 5 ])
const [ earth, citadel ] = await getLocation([ 1, 3 ])
const s01 = await getEpisode(Array.from({ length: 11 }, (v, i) => i + 1))
Filter
Pass an object with the queries.
To know more about filtering check the docs.
const aliveRicks = await getCharacter({
name: 'rick',
status: 'alive'
})
const planets = await getLocation({
type: 'planet',
page: 2
})
const seasonOne = await getEpisodes({
episode: 's01'
})
Get all
const chars = await getCharacter()
const locations = await getLocation()
const episodes = await getEpisode()
const moreChars = await getCharacter({ page: 2})
This method will response with the available endpoints, you can use it to ping the server status.