timefetcher
v1.0.0
Published
Displays how long it took to fetch from API's.
Readme
⏳ timefetcher
Displays how long it took to fetch from API's.
Installation
npm install timefetcherUsage
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:
millisecondssecondsminuteshours
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.
