wallace v0.0.2
Wallace
make ajax calls and return the result via callback it uses Axios and js-cookies under the hood and mereley configures the libraries to make use of JSON-Web-Token Functionality or dynamically add headers
It is planned that this module uses semantic versioning after version 1.0 since I am at the moment in the process of using promises instead of callbacks for the api, to be more in line with how Axios works by itself.
I am currently still figuring out how to build this using webpack that is the most convenient way, after i've settled on a process that seems to fit, I will release version 1 and then I'll try to enhance the module by adding features and making it more maintainable for myself.
how to use:
import into your project:
import wallace from 'wallace';
or
var wallace = require('wallace');
create a new object and pass optional config Object:
let wallaceInstance = new wallaceInstance({jwt_auth : true});
make calls like this:
wallaceInstance.get('http://www.someurl.com', callbackfunction);
or like this:
wallaceInstance.get('http://www.someurl.com', (response) => {
console.log(response);
//do more stuff with response.
});
the module will pass the response to the provided callback function,
api
so far the module supports the following methods
wallaceInstance.get('https://someurl', callback);
wallaceInstance.post('https://someurl', callback, {exampleObject : {exampleProperty : 'exampleData'}});
wallaceInstance.put('https://someurl', callback, {exampleObject : {exampleProperty : 'exampleData'}});
wallaceInstance.delete('https://someurl', callback, {exampleObject : {exampleProperty : 'exampleData'}});
configuration properties can be overriden on a by-call-basis. Just pass in an additional object during the appropriate method call:
wallaceInstance.get('https://someurl', callback, {jwt_auth: false});
wallaceInstance.post('https://someurl', callback, {exampleObject : {exampleProperty : 'exampleData'}}, {jwt_auth: false});
configuration
you can pass a config object into the constructor to override certain behavious like this:
let config = {
methodOverride : true,
headers : {
'custom-header-description' : 'custom-header-value'
}
}
let wallaceInstance = new wallaceInstance(config);
the following configuation properties are supported
{Boolean} methodOverride : (default: false) //if true, sets X-Http-Method-Override Header to send PUT and DELETE request via POST call for use with systems that only support GET and POST
{Object} headers: (default : {}) // can be used to set additional headers like this { headers : {'custom-header-description' : 'custom-header-value', 'custom-header-description2' : 'custom-header-value2' }}
{Boolean} rawError : (default : true) // if true returns the raw error Object if the request fails otherwise it tries to match the error to certain properties like message, description etc
{Boolean} jwt_auth : (default : false) // adds a jwt-auth header to the request. It will look in cookies if a header exists and then add this to the request.
{String} jwt_key : (default : Math.random()) // used as key under which the jwt is saved as a cookie
{String} supress_warnings : (default : true) // set to false to output warning messages during usage
{String} baseUrl // sets a base url. any string passed to the actual call methods will be added to the base url
{Array} jwt_response_structure : (default: ['data'] )// if you use JWT and send the token via response, you can set the names of the nested properties via this configuration. ['level1', 'level2'] expects the response to be structured like this: { level1 : { level2 : 'JWT-Token-Value'}}
check the package.json for scripts and tests
please submit bugfixes or suggestion here via github issues