timefetcher

1.0.0 • Public • Published

⏳ timefetcher

Displays how long it took to fetch from API's.

Installation

npm install timefetcher

Usage

import timefetcher from 'timefetcher'

async function fetchData() {
  try {
    const url = 'https://api.spacexdata.com/v4/launches/upcoming';
    const data = await timefetcher(url, 'milliseconds', '✨ The URL returned a result, nice!');
  } catch (error) {
    console.error('Failed to fetch data:', error);
  }
}

fetchData();

API

timefetcherr(url[, timeUnit[, successMessage]])

Measures fetch time from the specified URL.

url (string):

The URL to fetch the data from.

const url = 'https://api.spacexdata.com/v4/launches/upcoming';

timeUnit (string, default: 'milliseconds')

Defines the unit in the default success message (by default, in milliseconds).

You can use the following:

  • milliseconds
  • seconds
  • minutes
  • hours
const data = await fetchtimer(url, 'seconds');

successMessage (string) (optional)

Defines a custom success message for when the URL returns a result.

const data = await fetchtimer(url, 'seconds', '✨ The URL returned a result, nice!');

License

Licensed under the MIT License.

/timefetcher/

    Package Sidebar

    Install

    npm i timefetcher

    Weekly Downloads

    0

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    3.42 kB

    Total Files

    4

    Last publish

    Collaborators

    • intter