1.1.1 • Published 4 years ago

marvel-random-hero v1.1.1

Weekly downloads
21
License
ISC
Repository
github
Last release
4 years ago

marvel-random-hero

stable

A simple interface around the Marvel Comics API, which returns random hero every time you call it.

demo - source

Motivation

This module has been created for the advanced backend course (node.js), of Keepcoding full stack web development bootcamp.

Install

npm install marvel-random-hero --save

Example

// Import module
const marvel = require ('marvel-random-hero');

// Initializes de module
const { randomCharacter } = marvel('xxx_public_key', 'yyy_private_key');

// Get random character
randomCharacter()
.then(character => console.log(character))
.catch(error => console.log(error));

Usage

To initialize the module you need to pass the public and private keys received while registering in Marvel Comics API. With this information, this module generates the hash required by Marvel API

// Creates the hash information for later calls
const auth = {
    ts: String(Date.now()),
    public: public,
    private: private,
    hash: ''
}
auth.hash = md5(auth.ts + auth.private + auth.public);

Later calls to randomCharacter will not pass your private key over the internet. Marvel API requires only sending the original timestamp (use to generate the md5 hash), the public key and the hash:

// Get random character and returns JSON information
// being endpoint: https://gateway.marvel.com:443/v1/public/characters
response = await axios({
    url: `${endpoint}?limit=1&offset=${random}&ts=${auth.ts}&apikey=${auth.public}&hash=${auth.hash}`,
    method: 'get'
})
1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago