import {Plugin} from '@nuxt/types' import Hydra from '../../services/hydra' declare module '@nuxt/types' { interface Context { $rest: { [key: string]: any } } } const restPlugin: Plugin = (ctx) => { const getCollection = async (uri: string) => { const responseQuery = await ctx.$http.get(`${uri}`); return await queries(responseQuery); } const getItem = async (uri: string, id: number) => { const query = await ctx.$http.get(`${uri}/${id}`); return await queries(query); } const queries = async (responseQuery: any) => { try { let response = await responseQuery.json(); return Hydra.parse(response); } catch (err) { console.log(err) } } ctx.$rest = { 'getCollection': getCollection, 'getItem': getItem } } export default restPlugin