43 lines
1.1 KiB
TypeScript
43 lines
1.1 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 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, getToc };
|