β οΈ Beta version!! Do not use in production!!
Simple and scalable service layer(with cache π€©) for Vue REST clients
- π₯ Suports Vue.js 2 and 3 (in progress on branch
next
) - π Zero dependencies
- π Typescript support
- π Code coverage with >90%
import { create } from '@ouvue/core'
import { create } from '@ouvue/core'
const services = {
posts: {
async getAll () {
console.log('Getting posts...')
// You don't need to put on a try/catch, Ouvue does it for you π
const res = await window.fetch('https://jsonplaceholder.typicode.com/posts')
const result = await res.json()
return result
}
}
}
const api = create({ services })
export default {
async mounted () {
const posts = await this.getPosts()
console.log('Posts', posts)
window.setTimeout(async () => {
console.log(await this.getPosts())
}, 2000)
},
methods: {
async getPosts() {
return api.fetch('posts/getAll')
}
}
}
See this code live and check out examples folder
create(options)
- create instance ofOuvue
options signature{ services, cache: { strategy: 'inmemory' // default } }
create
return an object with a fetch
function and OuvueRender
component
fetch(key, payload, options)
- fetch executes a service.key: e.g. 'users/create' payload: e.g. { name: 'Igor' } options: e.g. { onlyNetwork: true } // if exists on cache, call the network and update the cache
<ouvue-render :action="action" :payload="payload" :options="options" />
- fetch executes a service but with component-based approache.g. <ouvue-render action="users/create" :payload="{ name: 'Igor' }" :options="{ onlyNetwork: true }" />
npm t
: Run test suitenpm start
: Runnpm run build
in watch modenpm run test:watch
: Run test suite in interactive watch modenpm run test:prod
: Run linting and generate coveragenpm run build
: Generate bundles and typings, create docsnpm run lint
: Lints codenpm run commit
: Commit using conventional commit style (husky will tell you to use it if you haven't π)