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

http-service-result

v1.0.4

Published

A TypeScript utility package for handling HTTP requests with a Result pattern and custom exceptions

Readme

HTTP Service Library

Esta biblioteca fornece uma solução robusta para requisições HTTP em TypeScript utilizando Axios, com tratamento padronizado de erros através de exceções customizadas e o padrão Result. O objetivo é facilitar a integração HTTP, tornando o código mais seguro e previsível.

Instalação

npm i http-service-result

ou

yarn add http-service-result

Principais Recursos

  • Padrão Result: Todas as operações retornam um objeto Resultado (Sucesso ou Falha), facilitando o tratamento explícito de erros.
  • Exceções customizadas: Diversas exceções para cenários HTTP comuns.
  • HttpClient configurável: Classe para requisições GET, POST, PUT, DELETE e upload de arquivos.
  • Tipagem forte: Totalmente escrito em TypeScript.

Uso

Importação

import { post, get, put, del, uploadFile } from 'http-service-result';

Exemplo de uso direto

const response = await post<Usuario>('/auth', {
  body: {
    usuarioOuEmail: props.usuarioOuEmail,
    senha: props.senha
  }
});

if (response.ehSucesso()) {
  // Acesso ao response.valor.data
} else {
  // Tratamento de erro
}

Exemplo GET

const resultado = await get<Produto[]>('produtos');
if (resultado.ehSucesso()) {
  const produtos = resultado.valor?.data;
} else {
  // resultado.erro contém a exceção customizada
}

Upload de Arquivo

const fileInput = document.querySelector('input[type="file"]');
if (fileInput?.files?.[0]) {
  const resultado = await client.uploadFile('upload', fileInput.files[0]);
  if (resultado.ehSucesso()) {
    // Sucesso no upload
  } else {
    // resultado.erro contém a exceção
  }
}

Padrão de Retorno

Todas as funções retornam um Resultado:

  • Sucesso<E, V>: contém o valor retornado em .valor
  • Falha<E, V>: contém a exceção em .erro

Você pode usar os métodos utilitários:

  • ehSucesso()
  • ehFalha()
  • aplicarNoValor(fn)

Exceções Personalizadas

As principais exceções disponíveis são:

  • HttpServicoExcecao
  • HttpTimeoutExcecao
  • HttpAcessoNegadoExcecao
  • HttpProibidoExcecao
  • HttpRedeExcecao
  • E outras para cenários de domínio

Todas herdam de uma classe base Excecao e possuem métodos utilitários para mensagem, stack e dados adicionais.

Utilitários

Você pode criar resultados manualmente:

const sucesso = ResultadoUtil.sucesso('valor');
const falha = ResultadoUtil.falha(new HttpServicoExcecao('Erro customizado'));

Contribuição

Contribuições são bem-vindas! Sinta-se à vontade para abrir issues ou pull requests.