rubi-fetch
v1.0.3
Published
rubiFetch module
Downloads
36
Readme
Rubillex/rubiFetch
My new Nuxt module for doing amazing things.
Quick Setup
- Add
rubi-fetch
dependency to your project
# Using pnpm
pnpm add rubi-fetch
# Using yarn
yarn add rubi-fetch
# Using npm
npm install rubi-fetch
- Add
rubi-fetch
to themodules
section ofnuxt.config.ts
export default defineNuxtConfig({
modules: [
'rubi-fetch'
]
})
That's it! You can now use $cyberiaApi in your Nuxt app ✨
Preparation
Add module the config to nuxt.config.ts
export default defineNuxtConfig({
...
rubiFetch: {
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(
() => $rubiFetch<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>`