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

callfor

v1.0.3

Published

Node.js http/https client

Downloads

3

Readme

callfor

Introduction

callfor is an light weight Node.js http/https client. This supports Promise as well as Async/Await. This can be use for fetching data from API or any http/https address as well as POST data. All request methods like GET, POST, PUT, DELETE are supported.

Features

  • Fetch/ GET data from API or http/https URL.
  • POST data to http/https URL.
  • PUT, DELETE Request supported.
  • Common error handling.
  • Data can be get in many format like Buffer, ArrayBuffer, JSON, UTF-8 or Readable Text.
  • No other dependencies excepts Node.js.

Documentation

Installation

npm install callfor

Use

GET Request

const callfor = require('callfor');
callfor('https://jsonplaceholder.typicode.com/posts').then(res => console.log(res));

Get Data In Different Format

const callfor = require('callfor');

//For Getting Data in UTF-8 String or Readable Text Format
callfor('https://jsonplaceholder.typicode.com/posts')
.then(res => res.utf8())
.then(res => console.log(res));

//For Getting Data in ArrayBuffer Format
callfor('https://jsonplaceholder.typicode.com/posts')
.then(res => res.arrayBuffer())
.then(res => console.log(res));

//For Getting Data in JSON Buffer Format
callfor('https://jsonplaceholder.typicode.com/posts')
.then(res => res.json())
.then(res => cosole.log(res))

Async/Await

cosnt asyncFunction = async () => {
    let data = await callfor('https://jsonplaceholder.typicode.com/posts');
    let utfData = await data.utf8();
    let arrayBufferData = await data.arrayBuffer();
    let jsonBufferData = await data.json();
}

POST Request

callfor('https://jsonplaceholder.typicode.com/posts', {
    method: 'POST',
    body: JSON.stringify({
	    title: 'sbr',
	    body: 'shohidul bari',
	    userId: 1
    }),
    headers: {
	   "Content-type":  "application/json; charset=UTF-8" 
    }
}).then(res => res.utf8()).then(res => console.log(res));

Async / Await

let resp = await callfor('https://jsonplaceholder.typicode.com/posts'){
    method: 'POST',
    body: JSON.stringify({
	    title: 'sbr',
	    body: 'shohidul bari',
	    userId: 1
    }),
    headers: {
	    "Content-type":  "application/json; charset=UTF-8"
    }
}
resp = await resp.utf8();
console.log(resp);

PUT / DELETE Request

Same as POST Request. Only method value will be change to DELETE or PUT. For DELETE request, Remove body attribute from params.

Main Response Format

In main response, Data will provided in Node Buffer format. This response also contain 3 utility function to change the format of data like utf8 string, ArrayBuffer, JSON Buffer.

{
  StatusCode: 200,
  RequestedUrl: 'http://localhost:3000/user',
  Data: <Buffer 7b 22 69 64 22 3a 31 30 31 2c 22 6e 61 6d 65 22 3a 22 73 68 6f 68 69 64 75 6c 20 62 61 72 69 22 2c 22 64 65 70 74 22 3a 22 69 63 74 22 2c 22 64 65 67 ... 11 more bytes>,
  utf8: [Function],
  json: [Function],
  arrayBuffer: [Function]
}

Utility Function Provided With Response

  • utf8() : Readable Text or String Fromat.
  • json() : implemented buffer.toJSON() method to format as JSON Buffer.
  • arrayBuffer(): ArrayBuffer / Uint8Contents Format.