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

@valkyriestudios/net

v1.14.0

Published

A lightweight promise-based XHR module

Downloads

216

Readme

!!!Take Note: This library is in maintenance mode - Since its inception Fetch has become more and more the accepted standard!!!

@valkyriestudios/net

codeql npm npm

A lightweight promise-based network module.

npm install @valkyriestudios/net

##Performing an XHR call

Performing an XHR call is as easy as calling the method on the Net class and piping it to a resolve/reject

Net.get('https://my.funky.api/myfunkyendpoint').then(
	(response) => console.log(response.data),
	(error) => { ... }
);

Functionality

Net.configure(options={})

Configures global options for the Net class, any subsequent XHR call done through the Net proxy wrapper will use these new configuration options.

Net.get(url, options={})

Performs a GET xhr call to the passed url with the options as an optional configuration

Net.post(url, data, options={})

Performs a POST xhr call to the passed url with the options as an optional configuration

Net.delete(url, options={})

Performs a DELETE xhr call to the passed url with the options as an optional configuration

Net.put(url, data, options={})

Performs a PUT xhr call to the passed url with the options as an optional configuration

Net.options(url, options={})

Performs a preflight OPTIONS call to the passed url with the options as an optional configuration

Net.head(url, options={})

Performs a HEAD call to the passed url with the options as an optional configuration

Net.request(url, options={})

Performs an xhr call to the passed url with the options as an optional configuration. The method that the XHR call will use can be defined in the options as (for example: {method:'Get'}). The following methods are accepted: ['Get','Put','Post','Delete','Options','Head']

Options

The possible options that can be passed are

  • base (default: false) Sets a base url to use as a prefix for each endpoint for example:
NET.configure({ base : 'https://myhappyapi.net' });
NET.get('/user/identity') // would make a call to https://myhappyapi.net/user/identity
  • headers (default: {}) Sets the headers to be used in the xhr call. These will be merged with any header already configured through NET.configure for example:
{'Authentication':'Bearer...'}
  • method (default: false) Sets the method to be used by the xhr call

  • onProgress (default: false) Sets a callback function to be executed every time a ProgressEvent is fired for example:

(evt) => console.log('uploaded :', (evt.loaded/evt.total)*100, '%')
  • params (default: false) Sets the query string parameters for a specific request for example:
NET.get('/user/identity', { params : {a: 1, b: 2}}); // would become : /user/identity?a=1&b=2
  • timeout (default: 10000) Sets the timeout in ms to be used for the xhr call

  • withCredentials (default: false) Sets the withCredentials property of the xhr call

  • responseType (default:'') Sets the response type to be used for the xhr call (will only be applied when using Net in browser/electron not in node), possible options: arraybuffer,blob,document,json,text

Response :

The response object has the following keys

  • data The data that the call responded with

  • headers The headers that were found on the response

  • status An object containing the status of a network call. Contains the code and statusmessage

Contributors