Mixins
Note: To import mixins on your components do as above:
import { ApiList, ApiForm} from 'vue-rest';
ApiList
The ApiList is responsible for implementing a route mandatory prop and the three following methods:
loadList(callback, errCallback):- Params: callback, errCallback
- Functionality: It uses
$apiprototype to do aGETrequest in the givenrouteand pass the response for the callback function if the response was successfully made, otherwise passes the error to the errCallback function.
deleteObj(objId, callback, errCallback):- Params: objId, callback, errCallback
- Functionality: It uses
$apiprototype to do aDELETErequest in the givenrouteconcatenated with theobjIdand passes the response for the callback function if the response was successfully made, then it emits adeleteevent with theobjId.
editObj(obj):- Params: obj
- Functionality: It just emits an
editevent with the givenobjin its value. Note: You should probably handle the emitted value to pass to a ApiForm instance
ApiForm
The ApiForm is responsible for implementing the methods for API requesting that usually a form does.
It requires a route prop and, for convenience, can handle two others props objId and obj. Both props are handled in mixin's created() hook, and the obj set the requestObj data to its value and the objId loads a new instance of a object to requestObjreturned from API in theload method.
See: https://vuejs.org/v2/guide/instance.html#Instance-Lifecycle-Hooks
The following methods are implemented through this mixin:
load(id, errCallback):- Params: id, errCallback
- Functionality: It does a
GETrequest to the givenroute/idand loads theresponse.datato therequestObjdata.
save(callback, errCallback):- Params: callback, errCallback
- Functionality: It passes the received
callbackanderrCallbackto one of the following methods:- If the
requestObjhas anid(requestObj.id):update(callback, errCallback):- Params: callback, errCallback
- Functionality: It uses the
$apiprototype to do aPATCHrequests using the givenrouteand passing therequestObjas payload, passing the success response to thecallbackfunction and if there's any error it passes the it to theerrCallbackfunction.
- Otherwise:
create(callback, errCallback):- Params: callback, errCallback
- Functionality: It does the same thing as the update method but instead of a
PATCHit does aPOSTto the API.
- If the