rickmortyapi
Advanced tools
Comparing version 0.3.0 to 1.0.0
{ | ||
"name": "rickmortyapi", | ||
"version": "0.3.0", | ||
"description": "A Rick and Morty API Node wrapper", | ||
"main": "src/index.js", | ||
"version": "1.0.0", | ||
"author": "Axel Fuhrmann", | ||
"description": "The Rick and Morty API JS client", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"engines": { | ||
"node": ">= 10.21.0" | ||
"node": ">= 10" | ||
}, | ||
"scripts": { | ||
"dev": "nodemon src", | ||
"test": "nyc ava --verbose && nyc report --reporter=lcov", | ||
"test:watch": "ava --watch --verbose" | ||
"dev": "tsc -p tsconfig.json --watch", | ||
"build": "rm -rf dist && tsc -p tsconfig.json --emitDeclarationOnly", | ||
"postbuild": "esbuild src/index.ts --platform=node --target=node10 --sourcemap --minify --bundle --outfile=dist/index.js", | ||
"lint": "eslint src/. --cache --fix", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"test:coverage": "jest --coverage", | ||
"test:size": "bundlesize", | ||
"docs": "typedoc", | ||
"docs:watch": "npm run docs -- --watch --preserveWatchOutput", | ||
"doctoc": "doctoc README.md", | ||
"prepare": "husky install" | ||
}, | ||
"author": "Axel Fuhrmann", | ||
"license": "MIT", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"ava": "^3.8.2", | ||
"coveralls": "^3.1.0", | ||
"eslint": "^5.16.0", | ||
"nodemon": "^1.19.4", | ||
"nyc": "^15.0.1" | ||
"@types/jest": "^27.0.1", | ||
"@types/node": "^16.6.1", | ||
"@typescript-eslint/eslint-plugin": "^4.29.1", | ||
"@typescript-eslint/parser": "^4.29.1", | ||
"bundlesize": "^0.18.1", | ||
"doctoc": "^2.0.1", | ||
"esbuild": "^0.12.20", | ||
"eslint": "^7.32.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"husky": "^7.0.0", | ||
"jest": "^27.0.6", | ||
"prettier": "^2.3.2", | ||
"ts-jest": "^27.0.4", | ||
"typedoc": "^0.21.5", | ||
"typescript": "^4.3.5" | ||
}, | ||
"bundlesize": [ | ||
{ | ||
"path": "./dist/index.js", | ||
"maxSize": "2 kB" | ||
} | ||
], | ||
"repository": { | ||
@@ -30,3 +56,4 @@ "type": "git", | ||
"node", | ||
"rick and morty" | ||
"rick and morty", | ||
"api" | ||
], | ||
@@ -36,3 +63,4 @@ "bugs": { | ||
}, | ||
"homepage": "https://github.com/afuh/rick-and-morty-api-node#readme" | ||
"homepage": "https://github.com/afuh/rick-and-morty-api-node#readme", | ||
"dependencies": {} | ||
} |
108
README.md
@@ -1,3 +0,3 @@ | ||
![Tests](https://github.com/afuh/rick-and-morty-api-node/workflows/Tests/badge.svg) | ||
[![Coverage Status](https://img.shields.io/coveralls/github/afuh/rick-and-morty-api-node/master.svg?style=flat-square)](https://coveralls.io/github/afuh/rick-and-morty-api-node?branch=feature%2Fcover) | ||
[![Tests](https://github.com/afuh/rick-and-morty-api-node/workflows/Tests/badge.svg)](https://github.com/afuh/rick-and-morty-api-node/actions?query=workflow:Tests) | ||
[![Coverage Status](https://img.shields.io/coveralls/github/afuh/rick-and-morty-api-node/master.svg?style=flat-square)](https://coveralls.io/github/afuh/rick-and-morty-api-node?branch=master) | ||
[![npm version](https://img.shields.io/npm/v/rickmortyapi.svg?style=flat-square)](https://badge.fury.io/js/rickmortyapi) | ||
@@ -9,39 +9,58 @@ [![npm downloads](https://img.shields.io/npm/dm/rickmortyapi.svg?style=flat-square)](https://npmjs.org/package/rickmortyapi) | ||
# The Rick and Morty API JavaScript client | ||
A JavaScript client for retrieving content from [The Rick and Morty API](https://rickandmortyapi.com). | ||
> Hey, did you ever want to hold a terry fold?, | ||
> I got one right here, grab my terry flap. | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
This is a Node wrapper to use the [The Rick and Morty API](https://rickandmortyapi.com) in your favourite JavaScript project. | ||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [Client Reference](#client-reference) | ||
- [Response schema](#response-schema) | ||
- [Examples](#examples) | ||
- [Get by Id](#get-by-id) | ||
- [Get by Ids](#get-by-ids) | ||
- [Get all](#get-all) | ||
- [Filter](#filter) | ||
- [Pagination](#pagination) | ||
- [Get endpoints](#get-endpoints) | ||
**To get started check the documentation on [rickandmortyapi.com](https://rickandmortyapi.com/documentation)** | ||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
## Installation | ||
`npm i rickmortyapi` or `yarn add rickmortyapi` | ||
`npm i rickmortyapi` | ||
or | ||
`yarn add rickmortyapi` | ||
## Usage | ||
```js | ||
import { getCharacter } from 'rickmortyapi' // getCharacter() | ||
import { getCharacter } from 'rickmortyapi' | ||
// or | ||
import shlaami from 'rickmortyapi' // shlaami.getCharacter() | ||
import * as 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. | ||
const plumbus = require('rickmortyapi') | ||
// a Plumbus will provide you with a lifetime of better living and happiness. | ||
``` | ||
All methods return a promise. | ||
## Client Reference | ||
https://javascript.rickandmortyapi.com | ||
- `getCharacter()` | ||
- `getEpisode()` | ||
- `getLocation()` | ||
## Response schema | ||
The response for each method contains the following structure. | ||
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](https://rickandmortyapi.com/documentation/#character-schema) | ||
```js | ||
{ | ||
// The HTTP status code from the API response | ||
data: {}, | ||
### Get by ID | ||
// 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 | ||
```js | ||
@@ -51,15 +70,23 @@ const rick = await getCharacter(1) | ||
const episodeOne = await getEpisode(1) | ||
``` | ||
// You can also use an array of IDs. | ||
### Get by Ids | ||
```js | ||
const theSmiths = await getCharacter([ 2, 3, 4, 5 ]) | ||
const [ earth, citadel ] = await getLocation([ 1, 3 ]) | ||
const [ earth, citadel ] = await getLocation([ 1 , 3 ]) | ||
const s01 = await getEpisode(Array.from({ length: 11 }, (v, i) => i + 1)) | ||
``` | ||
### Get all | ||
```js | ||
const characters = await getCharacters() | ||
const locations = await getLocations() | ||
const episodes = await getEpisodes() | ||
``` | ||
### Filter | ||
Pass an object with the queries. | ||
To know more about filtering check the [docs](https://rickandmortyapi.com/documentation/#filter-characters). | ||
To know more about filtering check the [API documentation](https://rickandmortyapi.com/documentation/#filter-characters) or the client [reference](https://javascript.rickandmortyapi.com/interfaces/interfaces.CharacterFilter.html). | ||
```js | ||
const aliveRicks = await getCharacter({ | ||
const aliveRicks = await getCharacters({ | ||
name: 'rick', | ||
@@ -69,4 +96,3 @@ status: 'alive' | ||
// You can pass page number inside the object | ||
const planets = await getLocation({ | ||
const planets = await getLocations({ | ||
type: 'planet', | ||
@@ -76,3 +102,3 @@ page: 2 | ||
const seasonOne = await getEpisode({ | ||
const seasonOne = await getEpisodes({ | ||
episode: 's01' | ||
@@ -82,16 +108,10 @@ }) | ||
### Get all | ||
### Pagination | ||
In methods that return a paginated response (`getCharacters`, `getLocations` and `getEpisodes`), you can use a [`page`](https://rickandmortyapi.com/documentation/#info-and-pagination) property to access different pages. | ||
```js | ||
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 }) | ||
const moreCharacters = await getCharacters({ page: 2 }) | ||
``` | ||
- `getEndpoints()` | ||
This method will response with the available REST endpoints, you can use it to ping the server status. | ||
### Get endpoints | ||
`getEndpoints()`: This method will response with the available resouces, you can use it to ping the server status. |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
20874
14
154
113
16
2