1.1.1 • Published 1 month ago
cyberia-api v1.1.1
Cyberia API
My new Nuxt module for doing amazing things.
Quick Setup
- Add
cyberia-api
dependency to your project
# Using pnpm
pnpm add cyberia-api
# Using yarn
yarn add cyberia-api
# Using npm
npm install cyberia-api
- Add
cyberia-api
to themodules
section ofnuxt.config.ts
export default defineNuxtConfig({
modules: [
'cyberia-api'
]
})
That's it! You can now use $cyberiaApi in your Nuxt app ✨
Preparation
Add module the config to nuxt.config.ts
export default defineNuxtConfig({
...
cyberiaApi: {
accessTokenName: 'access-token',
baseUrl: 'https://example.com/'
},
})
accessTokenName is the name of the cookie storing your authorization token.
baseUrl needs no introduction
Usage
interface Response {
message: string;
data: string[];
}
const { data: testData } = await useAsyncData(
() => $cyberiaApi<Response>(`/test`)
);
console.log(testData.value.message);
In this case, the testData variable will contain the response from https://example.com/test.
If there is a cookie named access-token, the following line will be added to the request headers:
Authorization: `Bearer <access-token>`