Files
formex-viewer/frontend/src/lib/api.ts
2025-04-30 12:04:38 +02:00

58 lines
1.5 KiB
TypeScript

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<string> {
console.debug(
`Fetching article ${article} for CELEX ID ${celexId} in ${language} language`
);
const response = await axios.get<string>(
`${celexId}/articles/${article}/${language}`
);
return response.data;
}
async function getParagraph(
celexId: string,
article: number,
paragraph: number,
language: string
): Promise<string> {
console.debug(
`Fetching article ${article} paragraph ${paragraph} for CELEX ID ${celexId} in ${language} language`
);
const response = await axios.get<string>(
`${celexId}/articles/${article}/${paragraph}/${language}`
);
return response.data;
}
async function getArticleIds(celexId: string): Promise<number[]> {
console.debug(`Fetching article list for CELEX ID ${celexId}`);
const response = await axios.get<number[]>(`${celexId}/articles`);
return response.data;
}
async function getToc(
celexId: string,
language: Language
): Promise<Division[]> {
console.debug(`Fetching TOC for CELEX ID ${celexId}`);
const response = await axios.get<Division[]>(`${celexId}/toc/${language}`);
return response.data;
}
export { getArticle, getArticleIds, getParagraph, getToc };