GithubHelp home page GithubHelp logo

afuh / rick-and-morty-api-node Goto Github PK

View Code? Open in Web Editor NEW
170.0 6.0 34.0 1.25 MB

The Rick and Morty API JavaScript client

Home Page: https://javascript.rickandmortyapi.com

JavaScript 2.05% Shell 1.83% TypeScript 96.11%
rick-and-morty rickandmorty api-client

rick-and-morty-api-node's Introduction

Tests Coverage Status npm version npm downloads Twitter Follow

The Rick and Morty API JavaScript client

A zero dependency client for retrieving content from The Rick and Morty API.

Installation

Node 18 or above is required.

npm i rickmortyapi or yarn add rickmortyapi

Usage

import { getCharacter } from 'rickmortyapi'
// or
import * as shlaami from 'rickmortyapi' // shlaami.getCharacter()
// or
const plumbus = require('rickmortyapi')
// a Plumbus will provide you with a lifetime of better living and happiness.

Client Reference

Response schema

The response for each method contains the following structure.

{
  // The HTTP status code from the API response
  data: {},

  // The HTTP status message from the API response
  status: 200,

  // The response that was provided by the API
  statusMessage: 'OK',
}

Examples

All methods return a promise.

Get by Id

const rick = await getCharacter(1)
const earth = await getLocation(1)
const episodeOne = await getEpisode(1)

Get by 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))

Get all

const characters = await getCharacters()
const locations = await getLocations()
const episodes = await getEpisodes()

Filter

To know more about filtering check the API documentation or the client reference.

const aliveRicks = await getCharacters({
  name: 'rick',
  status: 'alive'
})

const planets = await getLocations({
  type: 'planet',
  page: 2
})

const seasonOne = await getEpisodes({
  episode: 's01'
})

Pagination

In methods that return a paginated response (getCharacters, getLocations and getEpisodes), you can use a page property to access different pages.

const moreCharacters = await getCharacters({ page: 2 })

Get endpoints

getEndpoints(): This method will response with the available resouces, you can use it to ping the server status.

Support

Help to maintain The Rick and Morty API's infrastructure.

If you want to know more about The Rick and Morty API click here.

rick-and-morty-api-node's People

Contributors

afuh avatar djelnar avatar ishibi avatar sueannioanis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rick-and-morty-api-node's Issues

Episodes 'character' type error

Hello, great job on the API, i've been using it for a personal project to create an app displaying rick and morty characters and episodes and i find it easy to use.

I have come across a bug - there seems to be a type error in the Episode interface found in interfaces.ts

the episode interface uses the name 'character' but the episodes schema uses 'characters', this causes a typescript error in my code when i use the Episode interface (see image attached)

Screenshot 2022-12-08 at 16 15 14

regeneration error

I'm having issues using this api in a react component. Every time i import the api with {getCharacter} i get this Reference Error: regenerationRuntime is not defined (what ever the hell that means) that crashes my app. what exactly is the content of the getCharacter because i know it's an object but of what exactly? Why I'm asking this is because i know the results from fetching the data from the api directly in my console give an object with two items (info and result) and then result is an array of objects. so what exactly is getCharacter an object of(an object of the fulfilled promise or the results array of objects

Uncaught Error: Cannot find module 'https'

I'm getting the following error when i'm calling getEpisodes()

Uncaught Error: Cannot find module 'https'
at webpackMissingModule (get.ts:1:1)
at ./node_modules/rickmortyapi/dist/index.js (get.ts:1:1)
at options.factory (react refresh:6:1)
at webpack_require (bootstrap:24:1)
at fn (hot module replacement:62:1)
at ./src/pages/episodes.tsx (characters.tsx:115:1)
at options.factory (react refresh:6:1)
at webpack_require (bootstrap:24:1)
at fn (hot module replacement:62:1)
at ./src/App.tsx (bundle.js:17:73)

clicking into the index.js stack trace takes me to the line

import https from 'https'

--

im using create react app, my package.json file

{
"name": "rick-and-morty",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.2",
"@types/node": "^16.18.3",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.4.3",
"react-scripts": "5.0.1",
"rickmortyapi": "^1.0.0",
"sass": "^1.56.1",
"sass-mq": "^6.0.0",
"typescript": "^4.9.3",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.