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

@ebcom/custom-request

v1.2.6

Published

this module use 3 module:

Downloads

6

Readme

@ebcom/custom-request is customized module for make http1.1 and http2, xml, http request from node js

this module use 3 module:

  • GOT version: 11
  • REQUEST PROMISE NATIVE version: 1.0.8

custom-request suport all methods for make http request

  ---- GET, POST, PUT, PATCH, DELETE, HED ----

Examples for make request with GOT agent and options you can use with got agent:

const cr = require('@ebcom/custom-request');
const options = {
      url: 'http://url.com',
      mehtod: 'POST',
      json: true,
      headers: {
            'Content-Type' : 'Application/json',
      },
      auth: {

      },
      query: {
            size: 10
      },
      timeout: 60 * 1000,
      retry: {},
      hooks: {},
      https: {},
      encoding: 'utf8',
      responseType: 'json',
      bodyOnly: true,
      throwErrors: false,
      context: {},
      body: {
            username: 'Ali'
      },
      form:{
            username: 'Ali',
      }
};

const http2 = false;
const agent = 'GOT'; // UpperCase or LowerCase

const response = await cr(options, http2, agent);

url: String path request.

method: Support all http method (GET, POST, PUT, PATCH, DELETE, HEAD). type string

headers: You cat set headers with this felid. type object

auth: Can pass Basic authorization and bearer authorization

auth: {
  user: 'username',
  pass: 'password',
}

or

auth:{
  username: 'username'
  password: 'password'
}

or

auth: {
  bearer: 'bearer token'
}

auth: {
  bearer: 'token'
}

query: You can set querystring with this felid. type object

timeout: Set timeout default is one minute. type number

throwErrors: (Boolean type) Throw HTTP errors, default is false

bodyOnly if you want get only the body should be this option true, default is false

retry: View github page for more info

hooks: View github page for more info

https: View github page for more info

encoding: You can set encoding type, default is 'utf8'.

responseType: You can set response type with 'json' or 'text', default is 'json'.

context: type object.

body: Set request body, type object.

form: Set request form. if set, the content-type header defaults to application/x-www-form-urlencoded.


Examples for make request with REQUEST agent:

const cr = require('custom-request');
const options = {
      url: 'http://url.com',
      mehtod: 'POST', // Can call function methos (GET, POST, PUT,...) or set in request options
      headers: {
            'Content-Type' : 'Application/json',
      },
      query: {
            size: 10
      },
      timeout: 60 * 1000,
      retry: {},
      hooks: {},
      https: {},
      encoding: 'utf8',
      responseType: 'json',
      resolveBodyOnly: true,
      context: {},
      body: {
            username: 'Ali'
      },
};

const agent = 'REQUEST'; // UpperCase or LowerCase

const response = await cr(options, http2, agent);

notice: You can't use http2 with REQUEST agent.


Use defaults method:

default method can set default some params like timeout, proxy and other...

Example:

const customRequest = require('custom-request');
const req = customRequest.default({agent: 'REQUEST', timeout: 3 * 1000, proxy: 'YOUR PROXY URL....'})
  • agent: You can initial object with default agent {'REQUEST', 'GOT'}. if you don't choose agent by default is 'GOT'