Skip to content

Ultra-lightweight wrapper around XMLHttpRequest. You should probably use fetch (whatwg-fetch) or RxJS, though.

License

Notifications You must be signed in to change notification settings

radiosilence/xr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

==
xr
==

Really simple wrapper about XHR that provides a couple of nice functions,
exposes the XHR object wherever relevant, and returns an ES6 Promise (or
whatever Promise is set to globally, if you want to use something else).

Quickstart
----------

    xr.get('/api/items', {take: 5})
      .then(res => console.log(res.data));
    
    xr.post('/api/item', {name: 'hello'})
      .then(res => console.log("new item", res.data));

Extended syntax:

    xr({
      method: xr.Methods.GET,
      url: '/api/items',
      params: {take: 5},
      events: {
        progress: (xhr, xhrProgressEvent) => {
          console.log("xhr", xhr);
          console.log("progress", xhrProgressEvent);
        }
      }
    });
    

API is simple, for now consult source files.

Features
--------

 * Returns ES6 promises.
 * Rejects if not 200.
 * Has query parameter generation.
 * Supports events.

Alias Methods
-------------

You can do some quick aliases to requests, for instance:
    
    xr.get('/my-url')

Requirements
------------

There must be a polyfill that supports at least the standard ES6 promise API
(xr will use whatever's there), and Object.assign().

License
-------

See LICENSE

About

Ultra-lightweight wrapper around XMLHttpRequest. You should probably use fetch (whatwg-fetch) or RxJS, though.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published