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

xhr.js

v1.0.2

Published

xhr.js is a library(<2Kb) to make AJAX/HTTP restful requests from client-side JavaScript with XMLHttpRequest.

Downloads

7

Readme

xhr.js

xhr.js is a library(< 2Kb) to make AJAX/HTTP restful requests with XMLHttpRequest. It has similar API with Python-requests.

Build Status npm npm npm

Usage

1. Install xhr.js

npm install xhr.js

2. import xhr.js

UMD import is supported, then get global object: XHR.

import XHR from 'xhr.js';

// or

var XHR = require("xhr.js");

or link with script in html files:

<script src="dist/xhr.min.js"></script>

3. use class XHR

var xhr = XHR(async); // default is async. you can set sync use  XHR(false)
xhr.on('success', function(result) {
	console.log('status_code:', result.status_code);
	console.log('status_text:', result.status_text);
	console.log('response_type:', result.response_type);

	console.log('text:', result.text);
	console.log('headers:', result.headers());
	console.log('json:', result.json()); // get the json result.
	console.log('xml:', result.xml());
});

xhr.get('package.json', params={'a': 'b'});

Detail API

1. XHR API

  1. xhr.request(method, url, body, onsuccess, onfail): request the url, with the method.
  2. xhr.on(): bind the request result(ready, error, success, fail), with result instance as it input.
  3. xhr.get(url, params, onsuccess, onfail): get request.
  4. xhr.post(url, params, onsuccess, onfail): post request.
  5. xhr.setRequestHeader(header_name, header_value): append a header.
  6. xhr.setAsync(aysnc): set request async / sync.
  7. xhr.url(): get the request url.
  8. xhr.body(): get the request body.
  9. xhr.abort(): abort request.
  10. xhr.reset(): reset the xhr instance, such url, headers, body, events.

2. XHR Event

  1. ready: when xhr is ready.
  2. error: when xhr can not be ready.
  3. success: when status_code is 200.
  4. fail: when status_code is not 200.

3. Response API (result)

  1. result.text: get all response text;
  2. result.status_code: the server response code;
  3. result.status_text: the server response code text, e.g. ok (status code is 200).
  4. result.response_type: response type;
  5. result.json: get the json object of response text;
  6. result.xml: get the xml object of response text;
  7. result.headers: get all the response headers object;

TODO

  • request auth
  • delete, put
  • a http test chrome plugin, like postman.

LICENSE

MIT