| 1 |
const jhdata = window.jhdata || {}; |
| 2 |
const base_url = jhdata.base_url || "/"; |
| 3 |
const xsrfToken = jhdata.xsrf_token; |
| 4 |
|
| 5 |
export const jhapiRequest = (endpoint, method, data) => { |
| 6 |
let api_url = new URL(`${base_url}api` + endpoint, location.origin); |
| 7 |
if (xsrfToken) { |
| 8 |
api_url.searchParams.set("_xsrf", xsrfToken); |
| 9 |
} |
| 10 |
return fetch(api_url, { |
| 11 |
method: method, |
| 12 |
json: true, |
| 13 |
headers: { |
| 14 |
"Content-Type": "application/json", |
| 15 |
Accept: "application/jupyterhub-pagination+json", |
| 16 |
}, |
| 17 |
body: data ? JSON.stringify(data) : null, |
| 18 |
}); |
| 19 |
}; |