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 🙏

© 2025 – Pkg Stats / Ryan Hefner

turtlefetch

v1.0.6

Published

Eaisily fetch from api with turtlefetch!

Readme

TurtleFetch

TurtleFetch is a lightweight and easy-to-use HTTP client that simplifies API fetching with built-in features like automatic retries, timeout handling, and flexible configuration. It works seamlessly in both Node.js and browser environments.

Features

  • 🌐 Base URL Support: Set a base URL for all API requests to avoid repetition.
  • 🔄 Automatic Retries: Automatically retries failed requests up to a configurable limit.
  • Timeout Handling: Aborts requests that exceed a specified timeout duration.
  • 🛠️ Convenience Methods: Includes get, post, put, and delete methods for common HTTP operations.
  • 🧰 Flexible Configuration: Easily configure headers, authentication tokens, and other options.

Installation

Install TurtleFetch via NPM:

npm install turtlefetch

Usage

Importing the Package

const TurtleFetch = require('turtlefetch');

Initialize TurtleFetch

Create an instance of TurtleFetch with a base URL and default options:

const apiClient = new TurtleFetch('https://api.example.com', { headers: { Authorization: 'Bearer YOUR_TOKEN', 'Content-Type': 'application/json', }, });

Make API Requests

GET Request

apiClient.get('/data') .then((data) => console.log('GET Response:', data)) .catch((error) => console.error('GET Error:', error));

POST Request

apiClient.post('/data', { key: 'value' }) .then((response) => console.log('POST Response:', response)) .catch((error) => console.error('POST Error:', error));

PUT Request

apiClient.put('/data/1', { key: 'updatedValue' }) .then((response) => console.log('PUT Response:', response)) .catch((error) => console.error('PUT Error:', error));

DELETE Request

apiClient.delete('/data/1') .then((response) => console.log('DELETE Response:', response)) .catch((error) => console.error('DELETE Error:', error));

Configuration Options

When initializing TurtleFetch, you can pass the following options:

| Option | Type | Description | | -------------- | -------- | ------------------------------------------------ | | baseURL | string | The base URL for all API requests. | | defaultOptions | object | Default options for all requests (e.g., headers). |

Advanced Features

Automatic Retries

If a request fails (e.g., due to network issues or server errors), TurtleFetch will automatically retry the request up to the specified number of retries.

Example:

apiClient.get('/unstable-endpoint', {}, 5) // Retry up to 5 times .then((data) => console.log(data)) .catch((error) => console.error(error));

Timeout Handling

You can specify a timeout duration (in milliseconds) for each request. If the request takes longer than this duration, it will be aborted.

Example:

apiClient.get('/slow-endpoint', {}, 3, 3000) // Timeout after 3 seconds .then((data) => console.log(data)) .catch((error) => console.error(error));

Error Handling

TurtleFetch throws an error if:

  • The request fails after all retries.
  • The server responds with a non-2xx status code.
  • The request times out.

Example:

apiClient.get('/nonexistent-endpoint') .catch((error) => { console.error('Error Message:', error.message); console.error('Stack Trace:', error.stack); });

Why Use TurtleFetch?

  • Simplifies repetitive tasks like setting headers and handling retries.
  • Provides robust timeout and error-handling mechanisms.
  • Lightweight and easy to integrate into any JavaScript or Node.js project.

Log

1.0.0 - released 1.0.1 - added log 1.0.2 - fixed readme.md punctuation 1.0.3 - fixed readme.md punctuation 1.0.4 - fixed readme.md punctuation 1.0.5 - fixed readme.md punctuation