Sha256: 64b522b79624ba1c06ae1a8a5ae26d5b1049a1fb8914371b2e0e228f0be3805b
Contents?: true
Size: 953 Bytes
Versions: 15
Compression:
Stored size: 953 Bytes
Contents
export function csrfToken() { return document.querySelector("[name=csrf-token]").content; } function jsonFetchOptions() { return({ method: "POST", headers: { "Content-Type": "application/json; charset=utf-8", "X-CSRF-Token": csrfToken() } }); } export async function postJson(url, data) { const options = { ...jsonFetchOptions(), method: "POST" }; if (data) { options.body = JSON.stringify(data); } const response = await fetch(url, options); return response.json(); } export async function putJson(url, data) { const options = { ...jsonFetchOptions(), method: "PUT" }; if (data) { options.body = JSON.stringify(data); } const response = await fetch(url, options); return response.json(); } export async function post(url, data) { const response = await fetch(url, { method: "POST", body: data, headers: { "X-CSRF-Token": csrfToken() } }); return response.json(); }
Version data entries
15 entries across 15 versions & 1 rubygems