Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
vue-easy-rest
Advanced tools
Vue-easy-rest is a NPM package for VueJs for managing data served by a CRUD REST API.
We created vue-easy-rest because existing packages did not fit our needs :
What we want is to have a model layer which adresses these issues :
[key]_id
, but VueJS should not have to care about that).https://www.npmjs.com/package/vue-easy-rest
They are 2 main classes you will work with with vue-easy-rest : ResourceType
and Resource
.
A Resource
represents an individual object in the API, and a ResourceType
is just a collection of resources.
ResourceType
The ResourceType
(or Collection
), is a list of items representing resources in the API (and most of the time lines in the database).
ResourceType
The constructor of ResourceType
takes two parameters :
route
(string): URL of the collection (absolute or relative)options
(Object, optional): Accepted keys =>
scope
: The scope of the collection, which is an object of parameters that will be sent to the API when getting the collection on the index route. No parameters if left empty.autosaveDisabled
: Boolean to trigger off the autosave functionanlity (default : false
)Examples :
answers = new ResourceType(`${window.location.origin}/answers`, { scope: {by_machine_node: 13} })
livechecks = new ResourceType(`/vue_api/livechecks`, { autosaveDisabled: true })
The method fetch
of a ResourceType
makes a GET
HTTP call on the index route of the collection. Upon getting a response, all local resources will be erased and replaced by the result of the request.
Examples :
await answers.fetch()
try {
await livechecks.fetch()
} catch (e) {
console.warn('Livechecks unavailable')
}
answers.fetch().then(reponse => { etc... })
livechecks.fetch().then(reponse => { etc... }).catch(err => { console.warn('Livechecks unavailable') })
Examples :
answers.models
(returns a javascript Array of Resource
)for (let answer of answers.models)
<div v-for="answer of answers.models" :key="answer.id">
Examples :
let instance = await instances.create({name: "New instance"})
let case_statement = await case_staments.create({name: "My super case statement", answer_id: 12})
Example : let input = await answers.inputs.push({name: "My super input"})
Resource
When fetching a ResourceType
, for each resource, we only get the data that the index route sends. Most of the time, the individual GET
route of a resource will send more information which is not sent in the index to prevent the response from being too big.
To test whether the resource has been individually loaded or not : answer.fullyLoaded()
(returns uan boolean)
Exemple : await answer.fetch()
Exemples :
await answer.delete()
await answer.destroy()
(exact same result, destroy
is just an alias for delete
)
Pro tip : Be careful not to use .delete()
in the template of a vue component. You could be surprised. Now I know you will try. Go aheadExemples :
answer.name = 'New name'
answer.inputs[2].reference = 'other'
<input v-model="answer.name">
PUT
requests are automatically performed by vue-easy-rest, except if the autosaveDisabled
option has been declared. In that case, the saveAll
method will force saving the object with all its children.
Resource
and ResourceType
provide a call
method that enable to make a call to a custom non-CRUD route
Exemples :
answer.call('check_integrity', 'GET', { anAdditionalParam: 42 }
(new ResourceType('instances')).call('all_available_languages', 'GET')
imageTemplate.call('deploy', 'PUT')
Sometimes, you already know which resource you need, but you don't need to actually perform a GET
to the index of that resource and THEN fetch the resource individually.
Exemples :
let answers = new ResourceType('/vue_api/answers');
let answer = answers.createModel({id: 12});
await answer.fetch();
createModel
locally pushes a new resource in the ResourceType
with the given attributes. Simillarily, there is a local findOrCreateModel
.
Now that you know more about vue-easy-rest, it's time for you to know that it's a wrapper around vue-mc. Resource
is an extension of Model
and ResourceType
is an extension for Collection
. That means you also have access to methods provided by vue-mc in their documentation : http://vuemc.io/#introduction
FAQs
Advanced model layer for a VueJS app with a REST API
We found that vue-easy-rest demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.