npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tolujimoh/request-multiple-urls

v0.1.2

Published

This package fetches the content of multiple urls and returns them in an array.

Downloads

3

Readme

Request Multiple Urls

This package fetches the content of multiple urls and returns them in an array.

NPM version

Installation

yarn add @tolujimoh/request-multiple-urls

Usage

requestMultipleUrls(url [, urlsOptions ] [, urlIndexOptions])

Where
  • urls is an Array of urls to be fetch
  • urlsOptions is the options that is applied to all provided urls
  • urlIndexOptions is an Object of options with index of targeted url (index in urls) as keys i.e the url that the options should be applied to
on success
  • returns urlContent as an array of Object or string

  • Response Object

    • httpStatus is the HTTP Status Code
    • body is the content of url
    • urlIndex is the index of url in urls
    • url is the url string
on failure
  • throws a TypeError, RangeError, or Error Error

  • Error Object

    • message is the error message
    • urlIndex is the index of url in urls
    • url is the url string
    • httpStatus is the HTTP Status Code (Optional)

Options

  • retries number
    • is the number of times a failed request should at most be retried, (default is 0)
  • retryInterval number
    • is the interval is ms between retires, (default is 1000ms)
  • responseType "json" | "text",
    • is the type the response that should be returned ("json" returns an Object, "text" returns a string)
Note

This module uses fetch to make http/https request. As such, all options from the fetch api is also available. Here is a link to the fetch documentation Link

Examples

const requestMultipleUrls = require('@tolujimoh/request-multiple-urls');

const urls = [
'https://ft-tech-test-example.s3-eu-west-1.amazonaws.com/ftse-fsi.json',
'https://ft-tech-test-example.s3-eu-west-1.amazonaws.com/gbp-hkd.json',
'https://ft-tech-test-example.s3-eu-west-1.amazonaws.com/gbp-usd.json'
];

requestMultipleUrls(urls, 
    {
        retries: 5, 
        retryInterval: 500,
        responseType: "json"
    }, {
        1: {
            retries: 3 
        }
    })
    .then(urlContent => {
        // on Success
    })
    .catch(error => {
        // on Failure
    });
with fetch API options
const requestMultipleUrls = require('@tolujimoh/request-multiple-urls');

const urls = [
'https://ft-tech-test-example.s3-eu-west-1.amazonaws.com/ftse-fsi.json',
'https://ft-tech-test-example.s3-eu-west-1.amazonaws.com/gbp-hkd.json',
'https://ft-tech-test-example.s3-eu-west-1.amazonaws.com/gbp-usd.json'
];

requestMultipleUrls(urls, 
    {
        retries: 3,
        // fetch api options
        headers: {
            "Authorization": "Bearer {token}"
        }
    })
    .then(urlContent => {
        // on Success
    })
    .catch(error => {
        // on Failure
    });

Dependencies

  • es6-promise
  • isomorphic-fetch

Development

Run tests

Navigate to project directory

$ yarn
$ yarn test

It has a 91.18% test coverage