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

questal

v3.0.4

Published

A lightweight javascript library for handling browser-based HTTP requests.

Downloads

18

Readme

questal

Downloads Version Size License

A lightweight javascript library for handling browser-based HTTP requests. For exclusively server-side requests, see Requestal

Install

npm install questal

Include

<!-- The old-fashioned way -->
<script type="text/javascript" src="/node_modules/dist/questal.min.js"></script>

<!-- By Es6 module -->
<script type="module" src="/node_modules/dist/questal.es.js"></script>
// Using Webpack/Babel loader or similar
import Questal from 'questal'

// straight into your javascript file
import Questal from '.node_modules/dist/questal.es.js';

Basic Usage:

You can make get, post, put, patch, and delete requests with Questal, to make a quick one off request you can capitalize the first letter and call the static version of the method, or you can set more customized options by instantiating a new Questal instance: :

//static request
Questal.Get('/path/to/dest', data => {
    console.log(data)
});

//using full Get method instance
const q = new Questal();  
let getInstance = q.get(options);
// do stuff
getInstance.send(url, data);

Pass parameters into the Questal constructor to have them persist through every call made by that instance, then optionally override a parameter on any individual call:

let post = q.post(
    {
        url:'/data',
        data: {
            id:16,
            first: 'Bill',
            last: 'Jones',
        }
    }
);

//Parameters sent: { url:'/data', data: { id:16, first:'Bill', last: 'Jones' } }
post.send();  

//Parameters sent: { url:'/params', data: { id:17, first:'Bill', last: 'Nelson' } }
post.send('/params', { id:17, last:'Nelson' });  

Callbacks

//static post request
Questal.Post('/path/to/dest', function(data) { console.log(data, data.json)});

The data parameter passed to the 'on success' callback is a Questal Response object containing the results of the request.

data:

QuestalResponse {
    defaultType: "text",
    settings: XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 60000, withCredentials: false, upload: XMLHttpRequestUpload, …},
    types: (5) ["arraybuffer", "blob", "document", "text", "json"],
    code: {…},
    data: {…},
    html: "…",
    json: {…},
    result: {…},
    status: "…",
    type: "…",
    url: "…",
    xml: "…",
}

data.json:

"names": [
    {
        "id": 1,
        "first": "Bill",
        "last": "Jones"
    },
    {
        "id":2,
        "first":"Jane",
        "last":"Smith"
    },
    {
        "id":3,
        "first":"Bob",
        "last":"Davis"
    }
]

Headers

Set or append header properties and they'll automatically be sent after open, for other tasks intended to run on readyState == 1, use questal.on('ready', callback)

let post = q.post('/data')

post.headers.accept = 'json'; //adds 'application/json' to acceptheaders to be set
post.headers.encoding = 'multipart'; // sets Content-Type to 'multipart/form-data'
post.response.type = 'json'; //sets response type to application/json

You can check the response object's headers parameter to confirm response headers:

post.on('responseHeaders', () => { // when readystate == 2
    if (post.response.headers.contentType != 'application/json') {
        console.log(headers); //print questal response header object to console
    }
});

//after setup, send request
post.send({ mykey: myValue });

Put and Delete

Turn the results of a request into its own file using the put method

let get = q.get('/path/to/dest');
get.on('success', (res) => {
    q.put('/data/data2.json', { file: res.text });
});

get.send();

Then add an event handler to delete the new file

document.getElementById('btn').addEventListener('click', function() {
    q.delete('/data/data2.json', res => (alert(res.text)));
});

Running npm run test-server will let you see some of these examples in action locally on localhost:8080 or 127.0.0.1:8080 in your browser.