import {$hydraParser} from '../../services/utils/hydraParser' import {NuxtHTTPInstance} from "@nuxt/http"; export class Rest{ private $http: NuxtHTTPInstance constructor($http: NuxtHTTPInstance) { this.$http = $http } public getCollection = async (uri: string) => { const responseQuery = await this.$http.get(`${uri}`); return await this.queries(responseQuery); } public getItem = async (uri: string, key: number|string) => { const query = await this.$http.get(`${uri}/${key}`); return await this.queries(query); } private queries = async (responseQuery: any) => { try { let response = await responseQuery.json(); return $hydraParser.parse(response); } catch (err) { console.log(err) } } } export const $rest = ($http: NuxtHTTPInstance) => new Rest($http)