How to use form-urlencoded - 10 common examples

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 soundcloud / soundcloud-javascript / src / api.js View on Github external
additionalParams.format = 'json';

    // set the oauth_token or, in case none has been issued yet, the client_id
    if (oauthToken) {
      additionalParams.oauth_token = oauthToken;
    } else {
      additionalParams.client_id = clientId;
    }

    // add the additional params to the received params
    addParams(params, additionalParams, isFormData);

    // in case of POST, PUT, DELETE -> prepare data
    if (method !== 'GET') {
      data = isFormData ? params : form.encode(params);
      params = { oauth_token: oauthToken };
    }

    // prepend `/` if not present
    path = path[0] !== '/' ? `/${path}` : path;

    // construct request url
    url = `${config.get('baseURL')}${path}?${form.encode(params)}`;

    return sendAndFollow(method, url, data, progress);
  },
github soundcloud / soundcloud-javascript / src / api.js View on Github external
oEmbed (trackUrl, options = {}) {
    // save element
    const element = options.element;
    delete options.element;

    options.url = trackUrl;

    // construct URL
    const url = `https://soundcloud.com/oembed.json?${form.encode(options)}`;

    // send the request and embed response into element if provided
    return sendAndFollow('GET', url, null).then((oEmbed) => {
      if (element && oEmbed.html) {
        element.innerHTML = oEmbed.html;
      }
      return oEmbed;
    });
  },
github soundcloud / soundcloud-javascript / src / api.js View on Github external
}

    // add the additional params to the received params
    addParams(params, additionalParams, isFormData);

    // in case of POST, PUT, DELETE -> prepare data
    if (method !== 'GET') {
      data = isFormData ? params : form.encode(params);
      params = { oauth_token: oauthToken };
    }

    // prepend `/` if not present
    path = path[0] !== '/' ? `/${path}` : path;

    // construct request url
    url = `${config.get('baseURL')}${path}?${form.encode(params)}`;

    return sendAndFollow(method, url, data, progress);
  },
github gaaiatinc / hapi-openid-connect / lib / userinfo / index.js View on Github external
function get_redirect_to_signin_with_error(query_error_message, redirect_descriptor) {
            let query_atring_obj = redirect_descriptor || {
                error: query_error_message
            };

            if (typeof query_atring_obj.redirect_uri === "string") {
                query_atring_obj.redirect_uri = decodeURIComponent(encodeUrl(query_atring_obj.redirect_uri));
            }

            return URL.format(user_info_endpoint.user_authentication_url + "?" + FormURLEncoder(query_atring_obj));
        }
github gaaiatinc / hapi-openid-connect / lib / authorization / index.js View on Github external
await __verify_client_registration_entries(authorization_request);
        /**
             * Now that the client_id and redirect_uri are verified, we validate the
             * authorization request and we can redirect with errors if any is found.
             */
        let processing_tasks = [__validate_authorization_request, authorization_endpoint.authorization_request_registrar_module.post_authorization_request];

        try {
            const authorization_request_id = await promiseSequencer(processing_tasks, authorization_request);
            /**
             * Everything is good to proceed for End-User authentication & consent:
             */
            let temp_redirect_uri = user_info_endpoint.user_authentication_url + "?authorization_request_id=" + encodeURIComponent(authorization_request_id);
            return h.redirect(temp_redirect_uri).takeover();
        } catch (auth_validation_error) {
            let temp_redirect_uri = authorization_request.redirect_uri + "?" + FormURLEncoder(auth_validation_error);
            return h.redirect(temp_redirect_uri).takeover();
        }
    } catch (client_validation_error) {
        let error_html = "   " + JSON.stringify(client_validation_error, null, 4) + "   ";
        return h
            .response(error_html)
            .code(401)
            .type("text/html");
    }
}
github gaaiatinc / hapi-openid-connect / lib / userinfo / index.js View on Github external
._id
                            .toString()
                    };

                    authorization_request_record.granted = true;
                    authorization_request_record.subject = user_account_id;

                    try {
                        await authorization_endpoint
                            .authorization_request_registrar_module
                            .put_authorization_request(authorization_request_record);

                        redirect_uri = URL.format(authorization_request_record.redirect_uri + "?" + FormURLEncoder(redirect_query_params));
                        return h.redirect(redirect_uri).takeover();;
                    } catch (err) {
                        redirect_uri = URL.format(authorization_request_record.redirect_uri + "?" + FormURLEncoder({error: "authorization request expired"}));
                        return h.redirect(redirect_uri).takeover();;
                    }
                } catch (err) {
                    redirect_uri = get_redirect_to_signin_with_error("Authorization request ID not found");
                    return h.redirect(redirect_uri).takeover();;
                }
            } else if (get_sanitized_redirect_uri(request.query["redirect_uri"])) {
                redirect_uri = get_sanitized_redirect_uri(request.query["redirect_uri"]);

                return h.redirect(redirect_uri).takeover();;
            } else {
                let reply_obj = {
                    status: "success",
                    status_code: 200,
                    status_message: "Signin successful"
                };
github Dwolla / dwolla-v2-node / src / dwolla / Token.js View on Github external
function getUrl(token, suppliedPath, suppliedQuery) {
  var url;
  if (typeof suppliedPath === "object") {
    url = suppliedPath._links.self.href;
  } else if (suppliedPath.indexOf(token.client.apiUrl) === 0) {
    url = suppliedPath;
  } else if (suppliedPath.indexOf("/") === 0) {
    url = [token.client.apiUrl, suppliedPath].join("");
  } else {
    url = [
      token.client.apiUrl,
      suppliedPath.replace(/^https?:\/\/[^\/]*\//, "")
    ].join("/");
  }
  var query = formurlencoded(rejectEmptyKeys(suppliedQuery || {}));
  return query ? [url, query].join("?") : url;
}
github Dwolla / dwolla-v2-node / src / dwolla / Auth.js View on Github external
function requestToken(client, params) {
  return fetch(client.tokenUrl, {
    method: "POST",
    headers: {
      "content-type": "application/x-www-form-urlencoded",
      "user-agent": require("../../src/dwolla/userAgent")
    },
    body: formurlencoded(
      assign(
        {
          client_id: client.id,
          client_secret: client.secret
        },
        params
      )
    )
  })
    .then(toJson)
    .then(handleTokenResponse.bind(null, client))
    .then(performOnGrantCallback.bind(null, client));
}

form-urlencoded

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

MIT
Latest version published 11 days ago

Package Health Score

80 / 100
Full package analysis