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

easy-http-client

v1.0.0

Published

Package to make http request very easy like jquery's Ajax

Downloads

4

Readme

easy-http-client

A lightweight and simple node js module for making web requets.

Features

  • Lightweight (0 dependencies)
  • Make http requests to any webserver
  • Custom request headers
  • Supports SSL
  • It's so easy to use like jquery's Ajax
  • Automated cookie storage (saves cookies from websites temporary and send them on every request to the same host)
  • Get and manage cookies

For what?

  • Use REST API's
  • Get HTML Content of a website
  • Sending data between your NodeJS App and a Webserver

Installation

First option

Install it with npm install easy-http-client

Second option

  1. Donwload the source code from GitHub
  2. Copy the main.js file in your project and require it

How to Use

Making a simple request

var easyHTTPClient = require('easy-http-client');
const client = new easyHTTPClient();

client.webRequest({
    method: 'GET',
    host: 'www.example.com',
    path: '/path/on/website.html',
    data: {'hello': 'world'},
    success: function(data, req){
        console.log(data);
    },
    error: function(err){
        console.error(err);
    }
});

Making an advanced request

var easyHTTPClient = require('easy-http-client');
const client = new easyHTTPClient();

client.webRequest({
    method: 'GET',
    host: 'www.example.com',
    port: 80,   //or 443 if you use ssl
    ssl: false, //true if you use ssl
    path: '/path/on/website.html',
    ignoreCookies: false,
    headers: {
        'Cookie': 'test=true',
        'Content-Type': 'application/json'
    },
    data: {'hello': 'world', 'more':'data'},
    queryString: 'some=data',
    success: function(data, req){
        console.log(data);
    },
    error: function(err){
        console.error(err);
    }
});

Documentation

webRequest(Object)

  • Object Object | required
    • method String | required | The HTTP Request Method (GET,POST,PUT,DELETE)

    • host String | required | The hostname of the server to which the request should go

    • port Integer | optional | The Port of the webserver of the host

    • ssl Boolean | optional | If you want to use ssl (use http or https)

    • path String | required | The Path in the URL

    • ignoreCookies Boolean | optional | If you want the cookies that come back with the request do not end up in the temporary cookie store

    • headers Object | optional | An Object with custom request headers

      • Header-Name String
      • Header-Value String
    • data Object | optional | An Object with the data that will be send on the request

      • name String
      • value String
    • queryString String | optional | Add some data to the request's query string

    • success(data, req) Function | required | Callen when the request is finished

      • data String | The body that returned from the webserver
      • req Object | The complete request data (with headers and such things)
    • error(err) Function | optional | Callen when something gone wrong

getCookies(host)

  • host String | required Get the cookies that stored in the cookie storage of a host

Retuns:

  • Object
    • data Array | An Array with the cookie strings with the cookies from this host
    • toObject() Function | A function that converts the cookie strings into beautiful javascipt objects

deleteCookies(host)

  • host String | required Delete the cookies that stored in the cookie storage of a host

getAllCookies()

Get all cookies from all hosts

Retuns:

  • Object
    • data Array | An Object with all hosts and an array with the cookie strings of the host inside
    • toObject() Function | A function that converts the cookie strings into beautiful javascipt objects

deleteAllCookies()

Delete all cookies

Some more examples

Get the cookies by host

var easyHTTPClient = require('easy-http-client');
const client = new easyHTTPClient();
//do your requests

var cookies = client.getCookies('some.host.com').data;
/*
Returns this:
[ 'name1=value1; expires=Wed, 05-Jun-2019 16:35:46 GMT; Max-Age=200',
  'name2=value2; expires=Wed, 05-Jun-2019 16:40:46 GMT; Max-Age=500' ]
*/

Get the cookies by host as object

var easyHTTPClient = require('easy-http-client');
const client = new easyHTTPClient();
//do your requests

var cookies = client.getCookies('some.host.com').toObject();
/*
Returns this:
[ { name1: 'value1' }, { name2: 'value2' } ]
*/

Get all cookies as object

var easyHTTPClient = require('easy-http-client');
const client = new easyHTTPClient();
//do your requests

var cookies = client.getAllCookies().toObject();
/*
Returns this:
{ hostname: [ { name1: 'value1' }, { name1: 'value1' } ] }
*/