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

ajaxclientjs

v1.0.1

Published

A lightweight, feature-rich AJAX client library that provides jQuery-like functionality with broad browser compatibility and modern features. This library offers a robust solution for handling HTTP requests in JavaScript applications.

Downloads

5

Readme

AjaxClient Library

License: MIT

A lightweight, feature-rich AJAX client library that provides jQuery-like functionality with broad browser compatibility and modern features. This library offers a robust solution for handling HTTP requests in JavaScript applications.

Support Me

This software is developed during my free time and I will be glad if somebody will support me.

Everyone's time should be valuable, so please consider donating.

https://buymeacoffee.com/oxcakmak

Features

  • 🚀 High Performance: Optimized request handling and caching system
  • 🔄 Request/Response Interceptors: Transform requests and responses globally
  • 💾 Smart Caching: Built-in caching system for GET requests
  • 🔁 Automatic Retry: Configurable retry mechanism for failed requests
  • 🌐 Cross-Browser Support: Works in all major browsers, including legacy versions
  • Promise-based API: Modern async/await support
  • 📊 Progress Tracking: Monitor upload and download progress
  • Request Cancellation: Cancel pending requests using AbortController
  • 🔄 Multiple Data Formats: Handles JSON, FormData, and URL-encoded data
  • 🛡️ Type Safety: Written in JavaScript with JSDoc annotations for better IDE support

Installation

npm install ajaxclientjs
# or
yarn add ajaxclientjs

For direct browser usage, include the script:

<script src="dist/AjaxClient.js"></script>

Quick Start

// Create an instance
const ajax = new AjaxClient({
  baseURL: 'https://api.example.com',
  headers: {
    'Authorization': 'Bearer your-token'
  }
});

// Make a GET request
ajax.get('/users')
  .then(response => console.log(response.data))
  .catch(error => console.error(error));

// Make a POST request
ajax.post('/users', {
  name: 'John Doe',
  email: '[email protected]'
})
  .then(response => console.log(response.data));

Advanced Usage

Configuration Options

const ajax = new AjaxClient({
  baseURL: 'https://api.example.com',
  headers: {
    'Authorization': 'Bearer token123'
  },
  timeout: 5000,           // 5 seconds
  retryAttempts: 3,        // Retry failed requests 3 times
  retryDelay: 1000,        // Wait 1 second between retries
  cache: true              // Enable caching for GET requests
});

Using Interceptors

// Request interceptor
ajax.addRequestInterceptor(options => {
  options.headers['X-Custom-Header'] = 'value';
  return options;
});

// Response interceptor
ajax.addResponseInterceptor(response => {
  response.data.timestamp = Date.now();
  return response;
});

Progress Tracking

ajax.post('/upload', formData, {
  onProgress: (event) => {
    const percent = (event.loaded / event.total) * 100;
    console.log(`Upload progress: ${percent}%`);
  }
});

Request Cancellation

const controller = new AbortController();

ajax.get('/large-data', {
  signal: controller.signal
});

// Cancel the request
controller.abort();

Caching

// Enable caching for specific request
ajax.get('/users', { cache: true });

// Clear cache
ajax.clearCache();

Multiple Data Formats

// JSON (default)
ajax.post('/api/data', { key: 'value' });

// FormData
const formData = new FormData();
formData.append('file', fileInput.files[0]);
ajax.post('/api/upload', formData);

// URL-encoded
ajax.post('/api/form', data, {
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});

API Reference

Constructor Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | baseURL | string | '' | Base URL for all requests | | headers | object | {} | Default headers | | timeout | number | 30000 | Request timeout in milliseconds | | retryAttempts | number | 0 | Number of retry attempts | | retryDelay | number | 1000 | Delay between retries in milliseconds |

Methods

Core Methods

  • request(url, options): Make a custom request
  • get(url, options): Make a GET request
  • post(url, data, options): Make a POST request
  • put(url, data, options): Make a PUT request
  • patch(url, data, options): Make a PATCH request
  • delete(url, options): Make a DELETE request

Utility Methods

  • addRequestInterceptor(interceptor): Add a request interceptor
  • addResponseInterceptor(interceptor): Add a response interceptor
  • abortAll(): Abort all pending requests
  • clearCache(): Clear the request cache

Request Options

| Option | Type | Description | |--------|------|-------------| | method | string | HTTP method | | data | any | Request payload | | params | object | URL parameters | | headers | object | Request headers | | timeout | number | Request timeout | | cache | boolean | Enable caching | | signal | AbortSignal | For request cancellation | | onProgress | function | Progress callback |

Browser Support

  • ✅ Chrome (latest)
  • ✅ Firefox (latest)
  • ✅ Safari (latest)
  • ✅ Edge (latest)
  • ✅ IE11 and above
  • ✅ Opera (latest)

Contributing

We welcome contributions!

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

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

Support