2022-04-19 06:33:45 +00:00
|
|
|
/*
|
|
|
|
|
This module is used by the /todos endpoint to
|
|
|
|
|
make calls to api.svelte.dev, which stores todos
|
|
|
|
|
for each user. The leading underscore indicates that this is
|
|
|
|
|
a private module, _not_ an endpoint — visiting /todos/_api
|
|
|
|
|
will net you a 404 response.
|
|
|
|
|
|
|
|
|
|
(The data on the todo app will expire periodically; no
|
|
|
|
|
guarantees are made. Don't use it to organize your life.)
|
|
|
|
|
*/
|
|
|
|
|
|
2022-07-07 19:32:55 +00:00
|
|
|
import { URLSearchParams } from 'url';
|
2022-04-19 06:33:45 +00:00
|
|
|
|
|
|
|
|
const base = 'https://api.boardgameatlas.com/api';
|
|
|
|
|
|
2022-07-07 19:32:55 +00:00
|
|
|
export function boardGameApi(
|
|
|
|
|
method: string,
|
|
|
|
|
resource: string,
|
|
|
|
|
queryParams: Record<string, string>,
|
|
|
|
|
data?: Record<string, unknown>
|
|
|
|
|
) {
|
2022-08-29 19:18:17 +00:00
|
|
|
// console.log('queryParams', queryParams);
|
2022-04-20 02:15:46 +00:00
|
|
|
queryParams.client_id = import.meta.env.VITE_PUBLIC_CLIENT_ID;
|
2022-07-07 19:32:55 +00:00
|
|
|
const urlQueryParams = new URLSearchParams(queryParams);
|
|
|
|
|
const url = `${base}/${resource}${urlQueryParams ? `?${urlQueryParams}` : ''}`;
|
2022-04-19 06:33:45 +00:00
|
|
|
return fetch(url, {
|
|
|
|
|
method,
|
|
|
|
|
headers: {
|
|
|
|
|
'content-type': 'application/json'
|
|
|
|
|
},
|
|
|
|
|
body: data && JSON.stringify(data)
|
|
|
|
|
});
|
|
|
|
|
}
|