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

flex-http-client

v1.0.3

Published

A flexible HTTP client adapter with TypeScript support

Readme

🌟 Flex HTTP Client

O flex-http-client é uma biblioteca TypeScript que abstrai a implementação de clientes HTTP, permitindo o uso flexível de axios ou fetch. Com tipagem robusta e uma interface simples, essa biblioteca facilita a realização de requisições HTTP em suas aplicações.

🚀 Instalação

Para instalar a biblioteca, execute o seguinte comando:

npm install flex-http-client

Se for utilizar o adaptador axios, certifique-se de instalar também o axios:

npm install axios

📦 Dependências

A biblioteca depende de axios caso você opte por usar o adaptador baseado nele, além de suportar a API nativa fetch.

🛠️ Como Usar

Aqui está um exemplo básico de como utilizar a biblioteca flex-http-client:

Exemplo com Axios

import { FlexHttpClient } from 'flex-http-client';

// Configurando o cliente com o adaptador axios
const axiosClient = new FlexHttpClient('axios', {
  baseURL: 'https://api.example.com',
  timeout: 5000,
});

// Realizando uma requisição GET
axiosClient.on().get('/data')
  .then(response => console.log(response))
  .catch(error => console.error(error));

Exemplo com Fetch

import { FlexHttpClient } from 'flex-http-client';

// Configurando o cliente com o adaptador fetch
const fetchClient = new FlexHttpClient('fetch', {
  baseURL: 'https://api.example.com',
});

// Realizando uma requisição GET
fetchClient.on().get('/data')
  .then(response => console.log(response))
  .catch(error => console.error(error));

Métodos Disponíveis

A biblioteca oferece métodos para as principais operações HTTP:

  • get<T>(url: string, config?: object): Promise<T> - Realiza uma requisição GET.
  • post<T>(url: string, data: any, config?: object): Promise<T> - Realiza uma requisição POST.
  • put<T>(url: string, data: any, config?: object): Promise<T> - Realiza uma requisição PUT.
  • delete<T>(url: string, config?: object): Promise<T> - Realiza uma requisição DELETE.
  • patch<T>(url: string, data: any, config?: object): Promise<T> - Realiza uma requisição PATCH.
  • Métodos adicionais como options, head, connect, trace também estão disponíveis para operações mais avançadas.

Configurações de Adaptador

Você pode configurar o cliente HTTP para usar tanto o axios quanto o fetch de acordo com sua preferência ou necessidade.

Exemplo de Configuração com Axios

const axiosClient = new FlexHttpClient('axios', {
  baseURL: 'https://api.example.com',
  timeout: 5000,
  headers: { 'Authorization': 'Bearer token' },
});

Exemplo de Configuração com Fetch

const fetchClient = new FlexHttpClient('fetch', {
  baseURL: 'https://api.example.com',
  headers: { 'Authorization': 'Bearer token' },
});

Definindo BaseURL

Ambos os adaptadores permitem que você defina uma baseURL, o que facilita a reutilização do cliente para diversas requisições com o mesmo domínio base.

🔍 Tipagem em TypeScript

A biblioteca é totalmente escrita em TypeScript, fornecendo autocompletar, verificação de tipos e suporte a interfaces para garantir a qualidade do código. Cada método aceita e retorna dados devidamente tipados, o que melhora a experiência de desenvolvimento.

Exemplo de Tipagem

interface MyData {
  id: number;
  name: string;
}

axiosClient.on().get<MyData>('/data').then((data) => {
  console.log(data.id, data.name);
});

📜 Licença

Este projeto está licenciado sob a MIT License.


Para mais informações ou se você tiver dúvidas, por favor, abra uma issue no repositório oficial.