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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@albertdz/consumer

v2.3.0

Published

Consume third-party APIs through axios

Downloads

21

Readme

Consumer

Configurar endpoints

  1. Crear archivo consumer-setup.js en la raiz del proyecto
  2. Agregar el siguiente código
const setup = {
	baseUrl: 'https://restcountries.com',
	headers: {
		'Content-Type': 'application/json',
	},
	methods: {
		countries: {
			url: '/v3.1/all',
			method: 'GET',
		},
		getCountry: {
			url: '/v3.1/name/{name}',
			method: 'GET',
			args: ['name']
		},
	}
};

module.exports = setup;
  1. Modificar baseUrl por la URL de la API a consumir
  2. Agregar las cabeceras necesarias en headers
  3. En methods agregar los métodos a consultar, puede usar GET POST PUT PATCH DELETE
  4. Ahora puede agregar una baseUrl a cada método

Realizar consulta

  • Importar
import { request, getStatus, isSyncing, subscribe, unsubscribe } from '@albertdz/consumer'
  • Requerir
const { request, getStatus, isSyncing, subscribe, unsubscribe } = require('@albertdz/consumer')
  1. request Función que realiza la consulta
  2. getStatus Función para obtener el estado de la consulta, inicia en offline, los demas valores son pending error success
  3. isSyncing Función para saber si la consulta esta en progreso, es de tipo boolean
  4. subscribe Se subscribe a un evento status syncing
  5. unsubscribe Se da de baja a un evento status syncing
  • Realizar solicitud
const { request } = require('@albertdz/consumer')

const data = { name: 'Myanmar' };
const queryParams = { fullText: true };
const response = await request('getCountry', { data, queryParams });
  1. Data: Valores configurados en args
  2. queryParams: Valores para consultas avanzandas. Ejemplo: /name?fullText=true
  3. headers: Cabeceras personalizadas para las consultas. Ejemplo 'Authorization': 'Bearer {token}'
  4. bearer: Valor para la cabecera Authorization en caso de no pasarlo en headers
  5. baseUrl: Realiza una petición a una baseUrl diferente a la configurada en el consumer-setup.js