npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@netsells/vuex-rest-api-cache

v3.0.2

Published

Vuex Rest API action creator and cacher

Downloads

70

Readme

Vuex Rest API Cache

npm version Build Status codecov Mutation testing badge Netlify Status

Vuex Rest API action creator and model cacher

This module makes it easier to create Vuex store actions, mutators, getters and state for communicating with rest APIs.

Installation

yarn add @netsells/vuex-rest-api-cache

Setup

import Vuex from 'vuex';
import Vrac from 'vuex-rest-api-cache';

const modules = Vrac.createModules({
    posts: {
        baseUrl: `${ API_URL }/posts`,
        children: {
            comments: {
                baseUrl: `${ API_URL }/posts/:post_id/comments`
            },
        },
    },
});

const store = new Vuex.Store({ modules });

Documentation

Documentation is available here

Quick Usage

This includes usage examples for root models (e.g. /api/v1/posts) and for child models (e.g. /api/v1/posts/:post_id/comments)

Index

Get a list of models from the API. Will cache each model. Will always create a new API request instead of using the cache.

const posts = await this.$store.dispatch('posts/index');

const comments = await this.$store.dispatch('posts/comments/index', {
    fields: {
        post_id: 1,
    },
});

Create

Create a model. Will cache the model returned by the API. Will always create a new API request.

const post = await this.$store.dispatch('posts/create', {
    fields: {
        text: 'Foo bar',
    },
});

const comment = await this.$store.dispatch('posts/comments/create', {
    fields: {
        post_id: post.id,
        message: 'Foo bar',
    },
});

Read

Read a model. Will cache the model returned by the API. Will always use a cached model over reading from the API.

const post = await this.$store.dispatch('posts/read', {
    fields: {
        id: 45,
    },
});

const comment = await this.$store.dispatch('posts/comments/read', {
    fields: {
        post_id: post.id,
        id: 3,
    },
});

Update

Update a model. Will cache the model returned by the API. Will always create a new API request.

const post = await this.$store.dispatch('posts/update', {
    fields: {
        id: 45,
        text: 'Bar foo',
    },
});

const comment = await this.$store.dispatch('posts/comments/update', {
    fields: {
        post_id: post.id,
        id: 3,
        message: 'Hello world',
    },
});

Destroy

Destroy a model. Will remove the model from the cache. Will always create a new API request.

await this.$store.dispatch('posts/destroy', {
    fields: {
        id: 45,
    },
});

await this.$store.dispatch('posts/comments/destroy', {
    fields: {
        post_id: post.id,
        id: 3,
    },
});

Changing the HTTP Requests

Vrac sends all HTTP requests through Vrac.requestAdapter. By default, this passes the params straight through to axios.request. By overriding this function, you can either modify the request (e.g. to add authorization headers) or use a completely different HTTP library.

Vrac.requestAdapter = function(requestParams) {
    return axios.request(requestParams);
};