using NPM:
npm install https://github.com/Growish/gw-api-v2-client.git
using YARN:
yarn add https://github.com/Growish/gw-api-v2-client.git
GW2 class constructor need a configuration wich is provided by an object.
Example of the object needed:
options: {
baseUrl: 'https://apidev.growish.com/v2/client/girocredito/',
unauthorizedErr: () => {
window.location.href = '/';
},
handleSucces: (data) => {
return data;
},
defaultErr: (err) => {
alert(err.response.data.message);
},
requestErr: (errors, setErr) => {
setErr(errors.response.data.data);
},
onLoginSuccess: () => {
window.location.href = '/';
},
onLoginError: (error) => {
console.log(error);
},
onRegisterSuccess: () => {},
onRegisterError: (error) => {
console.log(error);
},
onLogoutSuccess: () => {},
onLogoutError: (error) => {
console.log(error);
},
badRequestErr: () => {},
forbiddenErr: () => {},
}
example of GW2 class initialization:
new GW2(options);
Where options is the configuration object.
request method:
client.request({
action:String,// the API method in CAPS example: "GETWALLETS"
params:Object,// object containing query string params
body:Object,// object containing the payload request body
setErrors:Function // function that saves the state of the errors in the UI component
urlParams:Object // url paramateres such as {ID} or path/{ID}/path
})
EXAMPLE:
client.request({
action:"CREATEWALLET",
//for this action, PARAMS is not mandatory
body:{currency: "EUR",goalAmount: 25000},
setErrors:setErrors // this is a frontend function reference.
//for this action, urlParams is not mandatory
})