0.0.11 • Published 5 months ago

rexhr v0.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Coverage Status

wtf?

Another client ajax library

first things first

All tests must run against a local small server, which needs to be started before running the tests.
NPM package clearly brings only the very minimal code (no tests code and no test server), but on the github repository there's everything:

> git clone https://fedeghe@github.com/fedeghe/rexhr.git
> cd rexhr
> yarn 
> yarn start // start the local server for tests

let it run and run the tests:

> yarn test

then You can shut down both.

add it and use it

run yarn add rexhr in the project where you want to try it, then import it:

var rexhr = require('rexhr');
rexhr.<http-verb>({
	url,					    // String
	body = null,			    // JSON, when the <verb> allows it
	headers = {}, 			    // one level JSON
	timeout = null				// Integer in ms
    withCreadentials = false    // Boolean
    user = null                 // String
    password = null             // String
	onCompleted = noop, 	    // ƒn
	onProgress = noop, 	    // ƒn
	onLoad = noop,              // ƒn
	onLoadstart = noop,         // ƒn
	onLoadend = noop,           // ƒn
	onError = noop,     	    // ƒn
	onAbort = noop,     	    // ƒn
	onTimeout = noop,   	    // ƒn
})

most common http-verbs

rexhr.delete({
	url: 'http://sampleurl/deleteSomething',
	body: {
		name: 'Henry',
		surname: 'Poincaré'
	}
	onCompleted: function(r){
		console.log((r.response);
	}
});
rexhr.get({
	url: 'http://sampleurl/gimmeSomething',
	onCompleted: function(r){
		console.log((r.response);
	}
});
rexhr.head({
	url: 'http://sampleurl/infoSomething',
	body: {
		name: 'Donald',
		surname: 'Knuth'
	}
	onCompleted: function(r){
		console.log((r.getResponseHeader("Content-Length"));
	}
});
rexhr.patch({
	url: 'http://sampleurl/patchSomething',
	body: {
		id: 12345
	}
	onCompleted: function(r){
		console.log((r.response);
	}
});
rexhr.post({
	url: 'http://sampleurl/postSomething',
	body: {
		m: 'Bob',
		f: 'Alice'
	}
	onCompleted: function(r){
		console.log((r.response);
	}
});
rexhr.put({
	url: 'http://sampleurl/putSomething',
	body: {
		num: 1
	}
	onCompleted: function(r){
		console.log((r.response);
	}
});

something extra

rexhr.getXML({
	url: 'http://sampleurl/text.xml',
	onCompleted: function(r){
		console.log((r.responseXML);
	}
});
rexhr.getJson({
	url: 'http://sampleurl/gimmejson',
	onCompleted: function(r){
		console.log((r.response);//already json
	}
});

2025 - rexhr

0.0.11

5 months ago

0.0.10

5 months ago

0.0.9

5 months ago

0.0.8

5 months ago

0.0.7

5 months ago

0.0.5

5 months ago

0.0.4

5 months ago

0.0.3

5 months ago

0.0.2

5 months ago

0.0.1

6 months ago

0.0.0

6 months ago