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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@breimerct/brex

v1.5.1

Published

[![npm version](https://img.shields.io/npm/v/@breimerct/brex.svg)](https://www.npmjs.com/package/@breimerct/brex) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

Readme

🌐 Brex

npm version License: MIT

A lightweight, type-safe HTTP client for JavaScript and TypeScript applications. Built on top of the Fetch API with extended functionality for modern web and Node.js applications.

✨ Features

  • 🚀 Simple and intuitive API
  • 📦 Tiny footprint with zero dependencies
  • 🔄 Request and response interceptors
  • ⚙️ Configurable defaults
  • 🔒 Type-safe with TypeScript generics
  • 🌐 Works in browsers and Node.js
  • ⏱️ Timeout support
  • 🛠️ Chainable instance configuration

📥 Installation

# Using npm
npm install @breimerct/brex

# Using yarn
yarn add @breimerct/brex

# Using pnpm
pnpm add @breimerct/brex

💻 Usage

🌱 Basic Example

import { GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS } from '@breimerct/brex';

// Simple GET request
GET('https://api.example.com/users').then((response) => {
  if (!response.error) {
    console.log(response.content);
  } else {
    console.error(response.error);
  }
});

// POST request with body
POST('https://api.example.com/users', {
  name: 'John Doe',
  email: '[email protected]',
}).then((response) => console.log(response.content));

// PUT request
PUT('https://api.example.com/users/1', {
  name: 'Updated Name',
}).then((response) => console.log(response.status));

// DELETE request
DELETE('https://api.example.com/users/1').then((response) =>
  console.log('User deleted:', !response.error),
);

// PATCH request
PATCH('https://api.example.com/users/1', {
  email: '[email protected]',
}).then((response) => {
  console.log('User updated:', !response.error);
});

// HEAD request
HEAD('https://api.example.com/users/1').then((response) => {
  console.log('Response headers:', response.headers);
});

// OPTIONS request
OPTIONS('https://api.example.com/users').then((response) => {
  console.log('Allowed methods:', response.headers['allow']);
});

📘 Using with TypeScript

interface User {
  id: number;
  name: string;
  email: string;
}

// Type-safe responses
GET<User[]>('https://api.example.com/users').then((response) => {
  const users = response.content;
  users.forEach((user) => console.log(user.name));
});

// Type-safe single response
GET<User>('https://api.example.com/users/1').then((response) => {
  const user = response.content;
  console.log(user.email);
});

⚙️ Creating a Custom Client

import { createBrexClient, Brex } from '@breimerct/brex';

// Create a custom client with configuration
const api = createBrexClient({
  baseURL: 'https://api.example.com',
  headers: {
    Authorization: 'Bearer your-token',
    'Content-Type': 'application/json',
  },
  timeout: 5000, // 5 seconds
});

// Use the custom client
api.get('/users').then((response) => console.log(response.content));

// Chain configuration methods
api
  .setHeader('X-API-Key', 'your-api-key')
  .setTimeout(10000)
  .get('/users/premium')
  .then((response) => console.log(response.content));

// Or use the Brex class directly
const client = new Brex({
  baseURL: 'https://api.example.com',
});

client.get('/users').then((response) => console.log(response.content));

🔌 Using Interceptors

import { createBrexClient } from '@breimerct/brex';

const api = createBrexClient({
  baseURL: 'https://api.example.com',
});

// Add request interceptor
api.addRequestInterceptor((config) => {
  console.log('Request:', config);
  // Add authentication token
  config.headers = {
    ...config.headers,
    Authorization: 'Bearer ' + localStorage.getItem('token'),
  };
  return config;
});

// Add response interceptor
api.addResponseInterceptor((response) => {
  console.log('Response:', response);
  // Transform response data
  if (response.content && !response.error) {
    response.content = response.content.data;
  }
  return response;
});

// Make requests with interceptors applied
api.get('/users').then((response) => console.log(response.content));

⚠️ Error Handling

import { GET } from '@breimerct/brex';

GET('https://api.example.com/users')
  .then((response) => {
    if (response.error) {
      console.error(`Error ${response.status}: ${response.error.message}`);
      console.error('Error code:', response.error.code);
      return;
    }

    console.log('Success:', response.content);
  })
  .catch((error) => {
    // This catches network errors or other exceptions
    console.error('Unexpected error:', error);
  });

📚 API Reference

🧰 Core Functions

  • GET<T>(url, config?): Make a GET request
  • POST<T>(url, body?, config?): Make a POST request
  • PUT<T>(url, body?, config?): Make a PUT request
  • DELETE<T>(url, config?): Make a DELETE request
  • createBrexClient(config?): Create a new instance with custom configuration

🏗️ HttpClient Class

The HttpClient class (exported as Brex) provides more control:

const client = new Brex({
  baseURL: 'https://api.example.com',
  headers: { 'Content-Type': 'application/json' },
  timeout: 30000,
});

🔨 Methods

  • get<T>(url, config?): Make a GET request
  • post<T>(url, body?, config?): Make a POST request
  • put<T>(url, body?, config?): Make a PUT request
  • delete<T>(url, config?): Make a DELETE request
  • patch<T>(url, body?, config?): Make a PATCH request
  • head<T>(url, config?): Make a HEAD request
  • options<T>(url, config?): Make an OPTIONS request
  • request<T>(config): Make a custom request

🔧 Configuration Methods

  • setBaseURL(url): Set the base URL
  • setHeaders(headers): Set multiple headers
  • setHeader(key, value): Set a single header
  • setParams(params): Set query parameters
  • setParam(key, value): Set a single query parameter
  • setTimeout(timeout): Set the request timeout
  • addRequestInterceptor(interceptor): Add a request interceptor
  • addResponseInterceptor(interceptor): Add a response interceptor

📝 Types

HttpResponse

interface HttpResponse<T> {
  content: T;
  error: HttpError | null;
  status: number;
}

HttpError

interface HttpError {
  message: string;
  status: number;
  code: string;
}

RequestConfig

interface RequestConfig {
  url: string;
  method: HttpMethod;
  headers?: HttpHeaders;
  params?: QueryParams;
  body?: any;
  timeout?: number;
}

👥 Contributing

Contributions are welcome! Here's how you can contribute to Brex:

🛠️ Setting up the Development Environment

  1. Fork the repository
  2. Clone your fork: git clone https://github.com/breimerct/brex.git
  3. Install dependencies: npm install
  4. Build the project: npm run build
  5. Run tests: npm run test

📈 Development Workflow

  1. Create a new branch: git checkout -b feature/your-feature-name
  2. Make your changes
  3. Build and test: npm run build
  4. Commit your changes: git commit -m "Add your feature description"
  5. Push to your fork: git push origin feature/your-feature-name
  6. Create a pull request to the main repository

📏 Code Style Guidelines

  • Follow the existing code style
  • Use TypeScript features appropriately
  • Write clear, descriptive comments
  • Use meaningful variable and function names

📤 Pull Request Process

  1. Update the README.md if needed
  2. Ensure all code is properly tested
  3. Make sure the code builds without errors or warnings
  4. Update the version in package.json following semantic versioning
  5. Your pull request will be reviewed by maintainers

📜 License

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

🤝 Contributors

✍️ Author

Breimer Correa [email protected]


Made with ❤️ by Breimer Correa