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

nuxt-jsonapi

v2.0.4

Published

Easy JSON:API client integration for Nuxt.js

Downloads

493

Readme

Nuxt JSON:API logo

nuxt-jsonapi

npm version npm downloads Github Actions CI Codecov License

Easy JSON:API client integration for Nuxt.js

📖   Release Notes

Version 2.x support Nuxt 3.x.

Version 1.x supports Nuxt 2.x

Introduction

nuxt-jsonapi adds easy JSON:API client integration to Nuxt. It is a loose wrapper around the excellent Kitsu JSON:API client.

This module globally injects a $jsonApi instance you can use to access the client anywhere using this.$jsonApi (options API) or const { $jsonApi } = useNuxtApp() (composition API).

Setup

  1. Add nuxt-jsonapi dependency to your project
yarn add nuxt-jsonapi # or npm install nuxt-jsonapi
  1. Add nuxt-jsonapi to the modules section of nuxt.config.js
{
  modules: [
    // Simple usage
    'nuxt-jsonapi',

    // With options
    [
      'nuxt-jsonapi',
      {
        baseURL: 'http://www.example.com/api',
        /* other module options */
      },
    ],
  ]
}
  1. If you didn't pass options with step #2, add a jsonApi object to your nuxt.config.js to configure module options:
export default {
  modules: ['nuxt-jsonapi'],

  jsonApi: {
    baseURL: 'http://www.example.com/api',
    /* other module options */
  },
}

❗ Important

If you do not specify a baseURL option, a default /jsonapi URL will be used. This is almost certainly not what you want so be sure it is set correctly.


Usage

Refer to Kitsu's excellent documentation for all the feature's the client offers.

You can access the client with:

Options API

this.$jsonApi

Example:

export default defineNuxtComponent({
  async asyncData({ $jsonApi }) {
    const { data } = await $jsonApi.get('/article')

    return {
      articles: data,
    }
  },
})

Composition API

const { $jsonApi } = useNuxtApp()

Example:

<script setup>
import { useNuxtApp, useAsyncData } from '#app'

const { $jsonApi } = useNuxtApp()

const { data: articles } = await useAsyncData(() => $jsonApi.get('/article'), {
  transform: ({ data }) => data,
})
</script>

Development

  1. Clone this repository
  2. Install dependencies using yarn install or npm install
  3. Start development server using yarn dev or npm run dev
  4. Run automated tests using yarn test or npm run test
  • Run npm run dev:prepare to generate type stubs.
  • Use npm run dev to start playground in development mode.

License

MIT License

Copyright (c) Patrick Cate