0.13.4 â€ĸ Published 8 months ago

cge-api-party v0.13.4

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

nuxt-api-party

nuxt-api-party

npm version

Nuxt 3 module to securely connect with any API.

Features

Setup

📖 Read the documentation

# pnpm
pnpm add -D nuxt-api-party

# npm
npm i -D nuxt-api-party

Basic Usage

📖 Read the documentation

Add this module nuxt-api-party to your Nuxt config and prepare your first API connection by setting an endpoint object with the following properties for the apiParty module option:

// `nuxt.config.ts`
export default defineNuxtConfig({
  modules: ['nuxt-api-party'],

  apiParty: {
    endpoints: {
      jsonPlaceholder: {
        url: process.env.JSON_PLACEHOLDER_API_BASE_URL!,
        // Global headers sent with each request
        headers: {
          Authorization: `Bearer ${process.env.JSON_PLACEHOLDER_API_TOKEN}`
        }
      }
    }
  }
})

If you were to call your API jsonPlaceholder, the generated composables are:

Use these composables in your templates or components:

<script setup lang="ts">
const { data, pending, refresh, error } = await useJsonPlaceholderData('posts/1')
</script>

<template>
  <h1>{{ data?.title }}</h1>
  <pre>{{ JSON.stringify(data, undefined, 2) }}</pre>
</template>

ℹī¸ You can connect as many APIs as you want, just add them to the endpoints object.

đŸ’ģ Development

  1. Clone this repository
  2. Enable Corepack using corepack enable
  3. Install dependencies using pnpm install
  4. Run pnpm run dev:prepare
  5. Start development server using pnpm run dev

Special Thanks

License

MIT License Š 2022-2023 Johann Schopplich

0.13.4

8 months ago

0.13.3

8 months ago

0.13.2

8 months ago