tshttp

JavaScript Object Oriented XHR Library


Keywords
xhr, ajax, micro, typescript, object, oriented
License
GPL-2.0
Install
bower install tshttp

Documentation

Object Oriented XHR Library

NPM version Bower version License

JavaScript XHR micro library written in TypeScript

Installation

Install tsHttp using npm:

npm i tshttp --save

Install tsHttp using bower:

bower i tshttp --save

Example Usage (umd)

require(['tsHttp'], function(http) {
    var HTTP = http.HTTP;

    var c = new HTTP.Client('https://my-cool-api.io/');

    c.get('some/sexy/endpoint', {with: {optional: ['query', 'strings']}}).then(function(response) {
        console.log(response.json);
    });

    var p = new HTTP.Pool(c, [
        (new HTTP.Request(HTTP.GET, {ep: 'some'})),
        (new HTTP.Request(HTTP.GET, {ep: 'array'})),
        (new HTTP.Request(HTTP.GET, {ep: 'of'})),
        (new HTTP.Request(HTTP.GET, {ep: 'batched'})),
        (new HTTP.Request(HTTP.GET, {ep: 'requests'}))
    ]);

    p.send().then(function(response, index) {
        console.log(response, index);
        /*
        Argument 1 is the repsonse object, and index is the index of the pool array.
        */
    });
})

Example Usage (node)

At the moment I'm using XMLHttpRequest and for Node to work you need to npm i XMLHttpRequest. And add XMLHttpRequest = (require('XMLHttpRequest')).XMLHttpRequest; before the require.

XMLHttpRequest = (require('XMLHttpRequest')).XMLHttpRequest;

var HTTP = (require('tsHttp')).HTTP;

var c = new HTTP.Client('https://my-cool-api.io/');

c.get('some/sexy/endpoint', {with: {optional: ['query', 'strings']}}).then(function(response) {
    console.log(response.json);
});

Building

To build:

  • npm i -g tsc
  • npm i -g rollup
  • npm i
  • npm run watch or npm run dev

npm run watch will clean the tmp and dev folders, build the dev version (npm run dev), and start watching. This file contains inline sourcemaps (what Rollup produce).

For a release: npm run build - which will minify, and run other optimization tasks over the file. This does not include source maps.