Socket
Socket
Sign inDemoInstall

@aspida/swrv

Package Overview
Dependencies
24
Maintainers
3
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @aspida/swrv

SWRV wrapper for aspida


Version published
Weekly downloads
118
increased by0.85%
Maintainers
3
Install size
21.6 kB
Created
Weekly downloads
 

Readme

Source

@aspida/swrv


aspida
npm version npm download



Getting Started

Installation

  • Using npm:

    $ npm install aspida @aspida/swrv @aspida/axios swrv axios
    # $ npm install aspida @aspida/swrv @aspida/fetch swrv
    # $ npm install aspida @aspida/swrv @aspida/node-fetch swrv node-fetch
    
  • Using Yarn:

    $ yarn add aspida @aspida/swrv @aspida/axios swrv axios
    # $ yarn add aspida @aspida/swrv @aspida/fetch swrv
    # $ yarn add aspida @aspida/swrv @aspida/node-fetch swrv node-fetch
    

Make HTTP request from application

src/index.vue

<template>
  <div>
    <div v-if="error">failed to load</div>
    <div v-if="!data">loading...</div>
    <div v-else>hello {{ data.name }}</div>
  </div>
</template>

<script lang="ts">
import { defineComponent } from "@vue/composition-api";
import useAspidaSWRV from "@aspida/swrv";
import aspida from "@aspida/axios"; // "@aspida/fetch", "@aspida/node-fetch"
import api from "../api/$api";

const client = api(aspida());

export default defineComponent({
  name: "Profile",

  setup() {
    const { data, error } = useAspidaSWRV(client.user._userId(123), { query: { name: "mario" } });

    return { data, error };
  },
});
</script>

Get response body/status/headers

src/index.vue

<template>
  <div>
    <div v-if="error">failed to load</div>
    <div v-if="!data">loading...</div>
    <template v-else>
      <div>Status: {{ data.status }}</div>
      <div>Headers: {{ JSON.stringify(data.headers) }}</div>
      <div>Name: {{ data.body.name }}</div>
    </template>
  </div>
</template>

<script lang="ts">
import { defineComponent } from "@vue/composition-api";
import useAspidaSWRV from "@aspida/swrv";
import aspida from "@aspida/axios"; // "@aspida/fetch", "@aspida/node-fetch"
import api from "../api/$api";

const client = api(aspida());

export default defineComponent({
  name: "Profile",

  setup() {
    const { data, error } = useAspidaSWRV(client.user._userId(123), "get", {
      query: { name: "mario" },
    });

    return { data, error };
  },
});
</script>

useAspidaSWRV(client.user._userId(123), { query }) is an alias of useAspidaSWRV(client.user._userId(123), "$get", { query })

Use with SWRV options

src/index.vue

<template>
  <div>
    <div v-if="error">failed to load</div>
    <div v-if="!data">loading...</div>
    <div v-else>hello {{ data.name }}</div>
  </div>
</template>

<script lang="ts">
import { defineComponent } from "@vue/composition-api";
import useAspidaSWRV from "@aspida/swrv";
import aspida from "@aspida/axios"; // "@aspida/fetch", "@aspida/node-fetch"
import api from "../api/$api";

const client = api(aspida());

export default defineComponent({
  name: "Profile",

  setup() {
    const { data, error } = useAspidaSWRV(client.user._userId(123), {
      query: { name: "mario" },
      revalidateDebounce: 0,
    });

    return { data, error };
  },
});
</script>

Dependent Fetching

const { data: user } = useAspidaSWRV(client.user);
const { data } = useAspidaSWRV(() => user.value && client.articles, {
  query: { userId: user?.id ?? 0 },
});

License

@aspida/swrv is licensed under a MIT License.

Keywords

FAQs

Last updated on 15 Aug 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc