How to use the form-urlencoded function in form-urlencoded

To help you get started, we’ve selected a few form-urlencoded examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jgillick / jira-changelog / src / Slack.js View on Github external
api(endpoint, method='GET', body=undefined) {
    const headers = {};
    const cachable = (method.toUpperCase() == 'GET');
    const url = `${API_ROOT}/${endpoint}?token=${this.config.slack.apiKey}`;

    if (!this.isEnabled()) {
      return Promise.reject('The slack API is not configured.');
    }

    if (typeof body === 'object') {
      body = urlencoded(body);
    }
    if (method === 'POST') {
      headers['Content-Type'] = 'application/x-www-form-urlencoded';
    }
    else if (cachable && cache[url]) {
      return Promise.resolve(cache[url]);
    }
    else if (method === 'GET' && pending[url]) {
      return pending[url];
    }

    pending[url] = fetch(url, { method, body, headers })
    .then(res => res.json())
    .then((data) => {
      // Cache result
      if (cachable && data && data.ok) {
github Datawheel / mondrian-rest-ui / src / lib / mondrian-utils.js View on Github external
export function aggregationQS(params) {
    const o = {
        drilldown: params.drilldown.map(l => l.full_name),
        measures: params.measures.map(m => m.name),
        cut: params.cut,
        nonempty: params.nonempty ? 'true' : 'false',
        distinct: params.distinct ? 'true' : 'false',
        parents: params.parents ? 'true' : 'false',
        debug: 'true' // TODO: debug enabled by default
    };
    return formurlencoded(o);
}
github mozilla / hubs / src / react-components / updates-dialog.js View on Github external
e.preventDefault();
      e.stopPropagation();
      if (!this.state.mailingListPrivacy) return;

      const url = "https://www.mozilla.org/en-US/newsletter/";

      const payload = {
        email: this.state.mailingListEmail,
        newsletters: "hubs",
        privacy: true,
        fmt: "H",
        source_url: document.location.href
      };

      await fetch(url, {
        body: formurlencoded(payload),
        method: "POST",
        headers: { "content-type": "application/x-www-form-urlencoded" }
      }).then(onSubmittedEmail);
    };
github unsplash / unsplash-js / src / utils / index.js View on Github external
export function formUrlEncode(body: Object): Object {
  return formurlencoded(body);
}
github thewca / tnoodle / tnoodle-ui / src / TNoodleApi.js View on Github external
this.showExt = function(title, scrambleRequest, password, ext, {target, doFetch}, competitionJson) {

        var body = {};
        body.sheets = JSON.stringify(scrambleRequest);
        if(password) {
            body.password = password;
        }
        body.generationUrl = location.href;
        let url = that.viewUrl + encodeURIComponent(title) + '.' + ext;

        body.schedule = JSON.stringify(competitionJson.schedule);

        if(doFetch) {
            return fetch(url, {
                method: "POST",
                body: formurlencoded(body),
                headers: {
                  'Content-type': 'application/x-www-form-urlencoded',
                },
            }).then(res => {
              if(res.status != 200) {
                return res.text().then(text => {
                  throw new Error(`Fetch returned ${res.status}: ${text}`);
                });
              }
              return res.blob();
            }).then(blob => { return {title, blob}; });
        } else {
            tnoodle.postToUrl(url, body, "POST", target);
        }
    };
    this.fetchPdf = function(title, scrambleRequest, password) {
github Datawheel / canon / packages / vizbuilder / src / containers / IssueButton.jsx View on Github external
const IssueButton = function({error, location, message, permalink, t}) {
  const issueParams = formUrlEncode({
    body: [
      `**Permalink**: ${location.origin + location.pathname}?${permalink}`,
      `**Error**: ${error}`,
      message ? `**Error details:** ${message}\n` : "",
      "**Detail of the issue:**\n"
    ].join("\n"),
    title: `[report/vizbuilder${location.pathname}] `
  });

  return (
    <AnchorButton
      href={`https://github.com/Datawheel/canon/issues/new?${issueParams}`}
      rel="noopener noreferrer"
      target="_blank"
      text={t("Vizbuilder.action_fileissue")}
    />
github Patreon / patreon-js / src / oauth.js View on Github external
function updateToken(params) {
    const url = buildUrl('/api/oauth2/token')
    const options = {
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'User-Agent': userAgentString()
        },
        body: formurlencoded(params),
        params: params,
        credentials: 'include',
        compress: false
    }

    return fetch(url, options)
        .then(checkStatus)
        .then(getJson)
        .then(json => {
            return (json.error)
                ? Promise.reject({
                    message: errMap(json.error, params),
                    body: json,
                    params
                })
                : Promise.resolve(json)
github stormpath / stormpath-widget / src / data / http / http-provider.js View on Github external
postForm(path, data, options) {
    if (!options) {
      options = {};
    }

    if (!options.headers) {
      options.headers = {};
    }

    options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
    options.headers['Accept'] = 'application/json';

    return this._createRequest({
      method: 'POST',
      path: path,
      body: formUrlencoded(data),
      ...options
    });
  }

form-urlencoded

Return an object as an 'x-www-form-urlencoded' string

MIT
Latest version published 6 months ago

Package Health Score

66 / 100
Full package analysis