Switch to Axios, Panel component test

This commit is contained in:
Adrian Rumpold
2025-04-29 07:33:01 +02:00
parent 3e5d465356
commit f113c72c10
9 changed files with 226 additions and 76 deletions

View File

@@ -1,6 +1,14 @@
import Axios from "axios";
import { API_URL } from "../constants";
import { Division, Language } from "./types";
const API_URL = import.meta.env.VITE_API_URL;
const axios = Axios.create({
baseURL: API_URL,
timeout: 5000,
headers: {
"Content-Type": "application/json",
},
});
async function getArticle(
celexId: string,
@@ -10,16 +18,16 @@ async function getArticle(
console.debug(
`Fetching article ${article} for CELEX ID ${celexId} in ${language} language`
);
const response = await fetch(
`${API_URL}/${celexId}/articles/${article}/${language}`
const response = await axios.get<string>(
`${celexId}/articles/${article}/${language}`
);
return await response.text();
return response.data;
}
async function getArticleIds(celexId: string): Promise<number[]> {
console.debug(`Fetching article list for CELEX ID ${celexId}`);
const response = await fetch(`${API_URL}/${celexId}/articles`);
return await response.json();
const response = await axios.get<number[]>(`${celexId}/articles`);
return response.data;
}
async function getToc(
@@ -27,8 +35,8 @@ async function getToc(
language: Language
): Promise<Division[]> {
console.debug(`Fetching TOC for CELEX ID ${celexId}`);
const response = await fetch(`${API_URL}/${celexId}/toc/${language}`);
return (await response.json()) as Division[];
const response = await axios.get<Division[]>(`${celexId}/toc/${language}`);
return response.data;
}
export { getArticle, getArticleIds, getToc };