Request Store¶
The Request Store is tied in with a series of middleware using Redux-Saga. This is designed to be used for simple get requests to the Cubed API, any additional requirements Axios with the request-builder helper can be used.
Request flow¶
When using the request store to make a request to the Cubed API there is a flow that happens using a series of Saga middleware which follows the outlined flow.
As part of this flow error handling is managed and will notify the user an error has occurred using the notification store. The nature of the error will also be provided in the Store as long as the error occurred on the return from the server and not due to programmer error.
How to invoke the flow¶
Importing getRequest
from /redux/actions/request can be done in a few ways based on if it's a single url, an object that needs to be passed into request builder or an array of either strings or objects.
This can not be provided an array with both strings and objects for the request builder.
getRequest('http://localhost:8042/i/v1/sales/?account=1');
getRequest(['http://localhost:8042/i/v1/sales/?account=1', 'http://localhost:8042/i/v1/product/?account=1']);
//Without additional parameters
getRequest({groupResource: 'api', groupName: 'sales'});
//With additional parameters
getRequest({groupResource: 'api', groupName: 'sales', params: [{key: 'date__lte', value:'2019-02-02'}]});
getRequest([{groupResource: 'api', groupName: 'sales'}, {groupResource: 'api', groupName: 'product'}]);
How to get data the flow¶
Once the data has been requested and cleaned the COMPLETE_REQUEST
action will be called. This will update the store with isLoading: false
therefore saying the data is ready. This can also occur when an error has been handled by the flow. Therefore, checking hasError: true
should be checked before assuming there is data. If there was a server error this can be accessed via data.message
.
If there are no errors then the data can be accessed as normal but the data has been cleaned to remove all request data, therefore only the request payload will be present.