Skip to content

sueannioanis/rick-and-morty-api-node

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status npm version npm downloads Twitter Follow

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' // getCharacter()
// or
import shlaami from 'rickmortyapi' // shlaami.getCharacter()
// or
const tinyRick = require('rickmortyapi')
// You can use the name that you desire,
// You could name it Plumbus for instance,
// because a Plumbus will provide you with a lifetime of better living and happiness.

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 an 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)

// You can also use an array of IDs.
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'
})

// You can pass page number inside the object
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()

// You can pass a page number to access all the pages inside the info object
// To know more about the info object and pagination, check
// https://rickandmortyapi.com/documentation/#info-and-pagination
const moreChars = await getCharacter({ page: 2})
  • getEndpoints()

This method will response with the available REST endpoints, you can use it to ping the server status.

About

The Rick and Morty API Node client

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%