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

jaxa

v2.1.0

Published

Jaxa is a lightweight NodeJS class wich can make transparents HTTP & HTTPS requests across the web.

Downloads

4

Readme

Jaxa

Jaxa is a lightweight NodeJS class wich can make transparents HTTP & HTTPS requests across the web.

Installation

Install Jaxa with npm

npm i jaxa

Documentation

Jaxa.request(url[, options][, callbacks])

Jaxa.request(options[, callbacks])

  • url <string>
  • options <Object>
  • callbacks <Object>
    • data <function>
    • end <function>
    • error <function>
    • callback <function>
  • Returns: <Promise>

Request method can be surchaged if you don't want to use an URL. options argument is based on the http & https nodejs documention, check the documention for more details. In addition, Jaxa allow callback fonctions during the lifecycle request.

[!NOTE] We added body attribute in options argument to provide you a way to send data. body accept ONLY string.

Constructor

Jaxa's constructor lets you define default parameters for future queries. They are not definitive and can be rewritten with each call.

Jaxa([, options][, callbacks])

Jaxa(options)

Jaxa(callbacks)

Callbacks

Callbacks can modify Jaxa comportement during his lifecycle. There is three hooks thats you can define:

  • data: Data callback give you chunk variable which is received during call consumption and data which is received content since the start of the query. By default, Jaxa concatenates these chunks into data variable.
  • end: End callback give you end variable. In simple terms, this is the result of concatenating the chunks, i.e. the final result of the query.
  • error: Error callback give you error variable, which describe error during request process.

[!TIP] Lifecycle hook can be overriden when callback attribute is declared in callbacks argument. callbackfunction give you three variables, first one is HTTP/HTTPS response, second and third are resolve and reject function of the promise.

Pre implemented methods

Pre implemented methods are simply a rewrite of arguments passed to requestfunction. They are listed below, along with the additions they make to objects.

| Methods | Request object passed | | :------- | :-------------------- | | get | { method: 'GET'} | | post | { method: 'POST'} | | put | { method: 'PUT'} | | delete | { method: 'DELETE'} | | connect | { method: 'CONNECT'} | | options | { method: 'OPTIONS'} | | trace | { method: 'TRACE'} | | patch | { method: 'PATCH'} | | head | { method: 'HEAD'} |

[!TIP] These functions can be called directly on the Jaxa instance. Check example below for more.

Example

const Jaxa = require('Jaxa');

const jaxa = new Jaxa();

// Historical Jaxa script function
jaxa.request('https://jsonplaceholder.typicode.com/posts/1')

// Pre implemented method 'POST'
jaxa.post('https://jsonplaceholder.typicode.com/posts', {
    method: 'POST',
    body: JSON.stringify({
        title: 'foo',
        body: 'bar',
        userId: 1,
    }),
    headers: {
    'Content-type': 'application/json; charset=UTF-8',
    }
})
.then(res => console.log(res))

// Pre implemented method 'PATCH' with redifined callback
jaxa.patch({
    body: JSON.stringify({
        title: 'foo',
    }),
    headers: {
        'Content-type': 'application/json; charset=UTF-8',
    },
    protocol: 'https:',
    hostname: 'jsonplaceholder.typicode.com',
    path: '/posts/1'
},
{
    callback: (res, resolve, reject) => {
        let data = '';

        res
        .on('data', (chunk) => {
            data += chunk;
        })
        .on('end', () => {
            resolve(data);
        })
        .on('error', (err) => {
            reject(err);
        })
    }
})
.then(res => console.log(res))