Files
traveldrafter/web/api.js
2025-06-18 15:26:47 +02:00

29 lines
634 B
JavaScript

export function fetchApi(pathcomponents, query) {
query.pretty = true;
let url = '/api/' + pathcomponents.join("/") + "?" + new URLSearchParams(query).toString();
return fetch(url).then(response => {
if (!response.ok) {
throw new Error("Fetching api failed");
}
return response;
}).then(response => response.json());
}
export function fetchLocations(query) {
return fetchApi(["locations"], {
query: query,
addresses: false,
poi: false,
subStop: false,
entrances: false,
linesOfStops: false,
});
}
export function fetchJourneys(from_, to) {
return fetchApi(["journeys"], {
from: from_,
to: to,
});
}