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

@sekizlipenguen/connection

v0.2.4

Published

A lightweight and promise-based HTTP client for React Native, React, and Web applications. Supports fetch and XMLHttpRequest with advanced configuration options.

Readme

platforms npm npm

@sekizlipenguen/connection

A powerful and customizable HTTP client designed for simplicity and flexibility in React Native, React, and Web environments. This library was created to address common challenges in RESTful API integrations, providing support for both fetch and XMLHttpRequest (XHR) as connection types. It includes features like upload progress tracking and a lightweight minified version (~5KB) for optimal performance. Perfect for handling both basic and advanced API needs, including file uploads, custom headers, and timeout management. With built-in logging, you can easily debug and monitor network requests, ensuring a seamless developer experience. Additionally, we have added the ability to toggle debug mode for React Native, allowing developers to easily activate or deactivate network monitoring, helping to address challenges in observing network activities during development.


Installation

Install the library using npm or yarn:

npm install @sekizlipenguen/connection
yarn add @sekizlipenguen/connection

Features

  • Supports both fetch and XMLHttpRequest (XHR) as connection types.
  • Global configuration for timeout and headers.
  • Event-driven progress handling for uploads.
  • Fully compatible with React Native 0.60+ and Web.
  • Lightweight and easy to use.
  • Logging functionality for debugging (optional).

Usage

Basic Example (GET Request)

import connection from "@sekizlipenguen/connection";

// GET request example
connection.get("https://example.com/api/data").then((response) => {
  console.log(response.data);
}).catch((error) => {
  console.error(error);
});

// Using async/await
async function fetchData() {
  try {
    const response = await connection.get("https://example.com/api/data");
    console.log(response.data);
  } catch (error) {
    console.error(error);
  }
}

fetchData();

POST Request Example

connection.post("https://example.com/api/data", {
  firstName: "John",
  lastName: "Doe",
}).then((response) => {
  console.log(response.data);
}).catch((error) => {
  console.error(error);
});

API Methods

| Method | Description | |----------|------------------------| | get | Sends a GET request | | post | Sends a POST request | | put | Sends a PUT request | | patch | Sends a PATCH request | | delete | Sends a DELETE request |

Each method accepts the following parameters:

  • url: The API endpoint.
  • data (optional): The payload for POST, PUT, PATCH requests.
  • config (optional): Configuration object (e.g., headers, timeout).

Global Configuration

You can set global configurations such as timeout and headers using setConfig.

connection.setConfig({
  timeout: 10000, // 10 seconds
  headers: {
    "Authorization": "Bearer token",
    "Content-Type": "application/json",
  },
});

Config Options

| Option | Type | Default | Description | |---------------|--------------------------|-----------|------------------------------------------| | connectType | 'fetch' | 'xhr' | 'fetch' | The connection type to use. | | headers | Record<string, any> | {} | HTTP headers for the request. | | timeout | number | 5000 ms | Request timeout in milliseconds. | | progress | (event: ProgressEvent) | null | Upload progress callback (for XHR only). | | logEnabled | boolean | false | Enable or disable logging for debugging. |


Advanced Example

Custom Headers and Timeout

connection.get("https://example.com/api/data", {
  headers: {
    "Authorization": "Bearer token",
  },
  timeout: 10000, // 10 seconds
});

Handling Progress Events (File Upload)

connection.post("https://example.com/api/upload", fileData, {
  headers: {
    "Content-Type": "multipart/form-data",
  },
  progress: (event) => {
    const percentCompleted = Math.round((event.loaded * 100) / event.total);
    console.log(`Upload progress: ${percentCompleted}%`);
  },
});

Enabling Logging

connection.enableLogs(true); // Enable logging
connection.enableLogs(false); // Disable logging

TypeScript Support

This library provides TypeScript definitions for better type safety and autocompletion.

Example

import connection, {Config, ReturnTypeConfig} from "@sekizlipenguen/connection";

const config: Config = {
    headers: {
        "Authorization": "Bearer token",
    },
    timeout: 10000,
};

async function fetchData() {
    try {
        const response: ReturnTypeConfig = await connection.get("https://example.com/api/data", config);
        console.log(response.data);
    } catch (error) {
        console.error(error);
    }
}

fetchData();

License

This project is licensed under the MIT License. See the LICENSE file for details.