Skip to content

johannschopplich/nuxt-api-party

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Nuxt API Party module

Nuxt API Party

Nuxt module that provides seamless integration with multiple API endpoints. It generates type-safe composables for each API endpoint you configure, offering a familiar developer experience similar to Nuxt's useFetch and $fetch while keeping your API credentials secure and eliminating CORS issues through a server proxy.

Features

Setup

npx nuxt module add api-party

Basic Usage

Add the 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:

  • $jsonPlaceholder โ€“ Returns the response data, similar to $fetch
  • useJsonPlaceholderData โ€“ Returns multiple values similar to useFetch

Use these composables in your templates or components:

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

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

Tip

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-PRESENT Johann Schopplich

MIT License ยฉ 2025-PRESENT Matthew Messinger

About

๐Ÿฌ Auto-generated composables for secure API access, with OpenAPI support

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 6