tshttp

0.1.6 • Public • Published

Object Oriented XHR Library

npm version bower version license

JavaScript XHR micro library written in TypeScript

Install with npm

$ npm i tshttp --save

Install with 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.

Dependencies (0)

    Dev Dependencies (6)

    Package Sidebar

    Install

    npm i tshttp

    Weekly Downloads

    0

    Version

    0.1.6

    License

    GPL-2.0

    Last publish

    Collaborators

    • marais