Init project
This commit is contained in:
28
web/api.js
Normal file
28
web/api.js
Normal file
@@ -0,0 +1,28 @@
|
||||
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,
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user