1.0.15 • Published 7 years ago

xhrt v1.0.15

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

XHRT (XMLHttpRequest Transfer)

npm version

The XHRTransfer allows you to send a service method passing a URL, a Data and a fallback, if necessary.

Using XHRT you can:

  • Send REST methods;
  • Pass data values to a method;
  • Pass a URL fallback if the first url fails;

Installation

Using like a library

$ git clone https://github.com/mpahenrique/xhrt.git
<body>
...
...
<script src="path/to/xhrt/index.js"></script>
</body>

Using like a module

$ npm install xhrt --save

Usage

Using like a module

var xhrt = require('xhrt');

Methods

GET

Usage:
xhrt.get(URL: string, DATA: object, FALLBACK: string).then(function(resolve){
    Callback();
    // Return success;
}, function(reject){
    Callback();
    // Return error;
});
Example:
xhrt.get('URL_TO_CALL', data_object, 'URL_TO_FALLBACK').then(function(resolve){
    console.log(resolve);
}, function(reject){
    console.log(reject);
});

POST

Usage:
xhrt.post(URL: string, DATA: object, FALLBACK: string).then(function(resolve){
    Callback();
    // Return success;
}, function(reject){
    Callback();
    // Return error;
});
Example:
xhrt.post('URL_TO_CALL', data_object, 'URL_TO_FALLBACK').then(function(resolve){
    console.log(resolve);
}, function(reject){
    console.log(reject);
});

PUT

Usage:
xhrt.put(URL: string, DATA: object, FALLBACK: string).then(function(resolve){
    Callback();
    // Return success;
}, function(reject){
    Callback();
    // Return error;
});
Example:
xhrt.put('URL_TO_CALL', data_object, 'URL_TO_FALLBACK').then(function(resolve){
    console.log(resolve);
}, function(reject){
    console.log(reject);
});

PATCH

Usage:
xhrt.patch(URL: string, DATA: object, FALLBACK: string).then(function(resolve){
    Callback();
    // Return success;
}, function(reject){
    Callback();
    // Return error;
});
Example:
xhrt.patch('URL_TO_CALL', data_object, 'URL_TO_FALLBACK').then(function(resolve){
    console.log(resolve);
}, function(reject){
    console.log(reject);
});

DELETE

Usage:
xhrt.delete(URL: string, FALLBACK: string).then(function(resolve){
    Callback();
    // Return success;
}, function(reject){
    Callback();
    // Return error;
});
Example:
xhrt.get('URL_TO_CALL', 'URL_TO_FALLBACK').then(function(resolve){
    console.log(resolve);
}, function(reject){
    console.log(reject);
});
1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

8 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.1

8 years ago