Add resources to your application; use requests to talk to an authenticated API or maybe access local storage. Resources offer just that, not web components in themselves, but a collection of ES6 class based exports for extending application functionality.
Create an MD5 hash
String md5(String s)
import CWCResourceCrypto from '/node_modules/custom-web-components/src/resource/CWCResourceCrypto.js';
// sha256 hash
const sha256 = CWCResourceCrypto.sha256('hello');
Create an sha256 hash
String sha256(String s)
import CWCResourceCrypto from '/node_modules/custom-web-components/src/resource/CWCResourceCrypto.js';
// sha256 hash
const sha256 = CWCResourceCrypto.sha256('hello');
Instantiate the instance
Object constructor(String baseName)
import CWCResourceRequest from '/node_modules/custom-web-components/src/resource/CWCResourceRequest.js';
// instantiate
let request = CWCResourceRequest('my-application');
Perform an ajax request
Promise ajax(String type, String url, Mixed data, Object headers)
import CWCResourceRequest from '/node_modules/custom-web-components/src/resource/CWCResourceRequest.js';
// instantiate
let request = CWCResourceRequest('my-application');
// raw ajax request
request.ajax('POST', 'http://your-api.com/account', { some: 'data' }, { 'Accept': 'application/json' })
.then((response) => console.log(response.data))
.catch((error) => console.log(error));
Perform a get request
Promise get(String path)
import CWCResourceRequest from '/node_modules/custom-web-components/src/resource/CWCResourceRequest.js';
// instantiate
let request = CWCResourceRequest('my-application');
// set up base URL for dedicated method
request.setBaseUrl('http://your-api.com');
// get request against a resource
request.get('account/1')
.then((response) => console.log(response.data))
.catch((error) => console.log(error));
Perform a put request
Promise get(String path, Mixed data)
import CWCResourceRequest from '/node_modules/custom-web-components/src/resource/CWCResourceRequest.js';
// instantiate
let request = CWCResourceRequest('my-application');
// set up base URL for dedicated method
request.setBaseUrl('http://your-api.com');
// put request against a resource with full dataset
request.put('account/1', { all: 'data', some: 'data' })
.then((response) => console.log(response.data))
.catch((error) => console.log(error));
Perform a patch request
Promise patch(String path, Mixed data)
import CWCResourceRequest from '/node_modules/custom-web-components/src/resource/CWCResourceRequest.js';
// instantiate
let request = CWCResourceRequest('my-application');
// set up base URL for dedicated method
request.setBaseUrl('http://your-api.com');
// patch request against resource with partial dataset
request.patch('account/1', { some: 'data' })
.then((response) => console.log(response.data))
.catch((error) => console.log(error));
Perform a post request
Promise post(String path, Mixed data)
import CWCResourceRequest from '/node_modules/custom-web-components/src/resource/CWCResourceRequest.js';
// instantiate
let request = CWCResourceRequest('my-application');
// set up base URL for dedicated method
request.setBaseUrl('http://your-api.com');
// post request new resource with full data
request.post('account', { all: 'data', some: 'data' })
.then((response) => console.log(response.data))
.catch((error) => console.log(error));
Perform a delete request
Promise delete(String path)
import CWCResourceRequest from '/node_modules/custom-web-components/src/resource/CWCResourceRequest.js';
// instantiate
let request = CWCResourceRequest('my-application');
// set up base URL for dedicated method
request.setBaseUrl('http://your-api.com');
// delete request against resource
request.delete('account/1')
.then((response) => console.log(response.data))
.catch((error) => console.log(error));
Perform a post request with multipart data
Promise upload(String path, Object files)
import CWCResourceRequest from '/node_modules/custom-web-components/src/resource/CWCResourceRequest.js';
// instantiate
let request = CWCResourceRequest('my-application');
// set up base URL for dedicated method
request.setBaseUrl('http://your-api.com');
// upload request a new resource
request.upload('account', [new FileObject()])
.then((response) => console.log(response.data))
.catch((error) => console.log(error));
Get current JWT token
String getToken()
import CWCResourceRequest from '/node_modules/custom-web-components/src/resource/CWCResourceRequest.js';
// instantiate
let request = CWCResourceRequest('my-application');
// set up base URL for dedicated method
request.setBaseUrl('http://your-api.com');
// get the current JWT token from local storage
let token = request.getToken();
Set JWT token in local storage
String setToken(String jwtToken)
import CWCResourceRequest from '/node_modules/custom-web-components/src/resource/CWCResourceRequest.js';
// instantiate
let request = CWCResourceRequest('my-application');
// set up base URL for dedicated method
request.setBaseUrl('http://your-api.com');
// set the current JWT token from local storage
let jwtToken = 'Token recieved when loggin in from login request';
request.setToken(jwtToken);
Has JWT token been set in local storage
Boolean hasToken()
import CWCResourceRequest from '/node_modules/custom-web-components/src/resource/CWCResourceRequest.js';
// instantiate
let request = CWCResourceRequest('my-application');
// set up base URL for dedicated method
request.setBaseUrl('http://your-api.com');
// set the current JWT token from local storage
console.log(request.hasToken());
Delete JWT token from local storage
deleteToken()
import CWCResourceRequest from '/node_modules/custom-web-components/src/resource/CWCResourceRequest.js';
// instantiate
let request = CWCResourceRequest('my-application');
// set up base URL for dedicated method
request.setBaseUrl('http://your-api.com');
// delete the current JWT token from local storage (such as logged out!)
request.deleteToken();
Set the base url and scheme on the instance
setBaseUrl(String value)
import CWCResourceRequest from '/node_modules/custom-web-components/src/resource/CWCResourceRequest.js';
// instantiate
let request = CWCResourceRequest('my-application');
// set up base URL for dedicated method
request.setBaseUrl('http://your-api.com');
Instantiate the instance
Object constructor(String baseName)
import CWCResourceStore from '/node_modules/custom-web-components/src/resource/CWCResourceStore.js';
// instantiate
let store = CWCResourceStore('my-application');
Has a thing from local storage ben set
Boolean hasItem(String key)
import CWCResourceStore from '/node_modules/custom-web-components/src/resource/CWCResourceStore.js';
// instantiate
let store = CWCResourceStore('my-application');
// Check is a key exists
console.log(store.hasItem('something.saved'));
Get a thing from local storage
Mixed hasItem(String key)
import CWCResourceStore from '/node_modules/custom-web-components/src/resource/CWCResourceStore.js';
// instantiate
let store = CWCResourceStore('my-application');
// Check is a key exists
console.log(store.getItem('something.saved'));
Set a value on local storage
Boolean setItem(String key, Mixed value)
import CWCResourceStore from '/node_modules/custom-web-components/src/resource/CWCResourceStore.js';
// instantiate
let store = CWCResourceStore('my-application');
// Check is a key exists
store.setItem('something.saved', { test: 'object' });
Delete a value on local storage
Boolean deleteItem(String key)
import CWCResourceStore from '/node_modules/custom-web-components/src/resource/CWCResourceStore.js';
// instantiate
let store = CWCResourceStore('my-application');
// Check is a key exists
console.log(store.deleteItem('something.saved');