@amjs/ajax-url 0.1.4
Object URL for any AJAX request
Installation
$ npm i @amjs/ajax-url
Usage
const AmjsAjaxURL = require('@amjs/ajax-url');
const url = new AmjsAjaxURL({
domain : 'some-domain',
port : 3000,
path : 'some-path/{id}',
params : {
id : 1,
key: 'value'
}
});
console.log(url.value); // 'https://some-domain:3000/some-path/1?key=value'
In order to use not secure protocol (http), set the 'unsecure' property to true
const AmjsAjaxURL = require('@amjs/ajax-url');
const url = new AmjsAjaxURL({
domain : 'some-domain',
port : 3000,
path : 'some-path/{id}',
params : {
id : 1,
key : 'value'
},
unsecure : true
});
console.log(url.value); // 'http://some-domain:3000/some-path/1?key=value'
Also you can add values assigning direct value:
const AmjsAjaxURL = require('@amjs/ajax-url');
const url = new AmjsAjaxURL();
url.value = {
domain : 'some-domain',
port : 3000,
path : 'some-path/{id}',
params : {
id : 1,
key : 'value'
},
unsecure : true
});
console.log(url.value); // 'http://some-domain:3000/some-path/1?key=value'