nuxt-api-party v2.0.0
Nuxt API Party
Nuxt module to securely connect to any API.
Features
- 🪅 Generated composables
- 🔒 Protected API credentials in the client
- 🪢 Token-based authentication built-in or bring your own headers
- 🧇 Connect multiple API endpoints
- 🍱 Feels just like
useFetch
- 🗃 Cached responses
- 🦾 Strongly typed
Setup
npx nuxi@latest 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 touseFetch
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>
!TIP You can connect as many APIs as you want, just add them to the
endpoints
object.
💻 Development
- Clone this repository
- Enable Corepack using
corepack enable
- Install dependencies using
pnpm install
- Run
pnpm run dev:prepare
- Start development server using
pnpm run dev
Special Thanks
- Dennis Baum for sponsoring the initial version of this package.
- Maronbeere for his logo pixel art.
License
MIT License © 2022-PRESENT Johann Schopplich
19 days ago
1 month ago
2 months ago
2 months ago
3 months ago
4 months ago
4 months ago
4 months ago
5 months ago
5 months ago
5 months ago
6 months ago
7 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
9 months ago
12 months ago
12 months ago
10 months ago
12 months ago
9 months ago
12 months ago
9 months ago
11 months ago
9 months ago
8 months ago
9 months ago
9 months ago
8 months ago
11 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
1 year ago
1 year ago
1 year ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago