Files
traveldrafter/web/api.js
2025-06-19 01:19:24 +02:00

35 lines
813 B
JavaScript

export function fetchApi(pathcomponents, query) {
console.log(pathcomponents);
query.pretty = true;
let url = '/api/' + pathcomponents.map(component => encodeURIComponent(component)).join("/") + "?" + new URLSearchParams(query).toString();
console.log(url);
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,
});
}
export function fetchTrip(trip_id) {
return fetchApi(["trips", trip_id], {});
}