import Axios from "axios"; import { API_URL } from "../constants"; import { Division, Language } from "./types"; const axios = Axios.create({ baseURL: API_URL, timeout: 5000, headers: { "Content-Type": "application/json", }, }); async function getArticle( celexId: string, article: number, language: string ): Promise { console.debug( `Fetching article ${article} for CELEX ID ${celexId} in ${language} language` ); const response = await axios.get( `${celexId}/articles/${article}/${language}` ); return response.data; } async function getParagraph( celexId: string, article: number, paragraph: number, language: string ): Promise { console.debug( `Fetching article ${article} paragraph ${paragraph} for CELEX ID ${celexId} in ${language} language` ); const response = await axios.get( `${celexId}/articles/${article}/${paragraph}/${language}` ); return response.data; } async function getArticleIds(celexId: string): Promise { console.debug(`Fetching article list for CELEX ID ${celexId}`); const response = await axios.get(`${celexId}/articles`); return response.data; } async function getToc( celexId: string, language: Language ): Promise { console.debug(`Fetching TOC for CELEX ID ${celexId}`); const response = await axios.get(`${celexId}/toc/${language}`); return response.data; } export { getArticle, getArticleIds, getParagraph, getToc };