Sha256: cc19dedda6fcad3a06bbe7e10421b2860f75bad5ff57b3ee288366a97e1e7aaf
Contents?: true
Size: 882 Bytes
Versions: 3
Compression:
Stored size: 882 Bytes
Contents
import { toURIParams } from "./obj"; const filterParams = data => { const params = {}; if (!data) return params; const forbidden = ["resource", "total", "count"]; Object.keys(data).forEach(prop => { if (forbidden.indexOf(prop) === -1) { params[prop] = data[prop]; } }); return params; }; export const sendReq = (httpMeth, url, data) => { const params = filterParams(data); const finalURL = httpMeth === "GET" ? `${url}?${toURIParams(params)}` : url; const meta = document.querySelector("meta[name='csrf-token']"); const req = new XMLHttpRequest(); req.open(httpMeth, finalURL); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json"); if (meta) { req.setRequestHeader("X-CSRF-Token", meta.content); } req.send(JSON.stringify(params)); return req; }; export default sendReq;
Version data entries
3 entries across 3 versions & 1 rubygems