@darwino/darwino
Version:
A set of Javascript classes and utilities
50 lines (42 loc) • 1.23 kB
JavaScript
/*!COPYRIGHT HEADER! - CONFIDENTIAL
*
* Darwino Inc Confidential.
*
* (c) Copyright Darwino Inc. 2014-2016.
*
* Notice: The information contained in the source code for these files is the property
* of Darwino Inc. which, with its licensors, if any, owns all the intellectual property
* rights, including all copyright rights thereto. Such information may only be used
* for debugging, troubleshooting and informational purposes. All other uses of this information,
* including any production or commercial uses, are prohibited.
*/
import Utils from "./Utils"
import {fetchJson} from './Fetch';
//
// Micro services class
//
class MicroServices {
name(name) {
this._name = name;
return this;
}
params(params) {
if(Utils.isString(params)) {
params = JSON.parse(params);
}
if(!Utils.isObject(params)) {
throw "Parameters is not a JSON object"
}
this._params = params;
return this;
}
fetch() {
// Use POST to be able to update data
const url = `$darwino-services?name=${encodeURIComponent(this._name)}`
return fetchJson(url, {
method: 'POST',
body: JSON.stringify(this._params || {})
})
}
}
export default MicroServices;