How to use the qs/lib/stringify function in qs

To help you get started, we’ve selected a few qs 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 page-pipepline / pipeline-editor / src / components / util / fetch.js View on Github external
if (options.method && /^POST|PUT|DELETE$/i.test(options.method)) {
    const params = options.body;
    if (options.headers['Content-Type'] === 'application/json') {
      options.body = JSON.stringify(params);
    } else if (options.headers['Content-Type'] === 'multipart/form-data') {
      delete options.headers['Content-Type'];
    } else {
      // 解决多层嵌套数据的问题
      options.body = stringify(params, { arrayFormat: 'brackets', skipNulls: true });
    }
  }

  // 处理get,默认get
  if ((options.method && /^GET$/i.test(options.method)) || options.method === undefined) {
    const params = options.params || options.body || {};
    url += `?${stringify(params, { arrayFormat: 'brackets', skipNulls: true })}`;
    // 解决某些浏览器下请求报错的问题 body not allowed for get or head requests
    options.body = undefined;
  }

  return fetch(url, options)
    .then((response) => {
      if (response.status === 200) {
        return response.json()
          .then((json) => {
            if (json.ret === '0') {
              return Promise.resolve(json.data);
            }
            return Promise.reject({
              status: response.status,
              ...json,
            });
github page-pipepline / pipeline-editor / src / components / util / fetch.js View on Github external
// 处理hearder
  options.headers = options.headers || {};
  if (!options.headers['Content-Type']) {
    options.headers['Content-Type'] = 'application/json';
  }

  // 处理post
  if (options.method && /^POST|PUT|DELETE$/i.test(options.method)) {
    const params = options.body;
    if (options.headers['Content-Type'] === 'application/json') {
      options.body = JSON.stringify(params);
    } else if (options.headers['Content-Type'] === 'multipart/form-data') {
      delete options.headers['Content-Type'];
    } else {
      // 解决多层嵌套数据的问题
      options.body = stringify(params, { arrayFormat: 'brackets', skipNulls: true });
    }
  }

  // 处理get,默认get
  if ((options.method && /^GET$/i.test(options.method)) || options.method === undefined) {
    const params = options.params || options.body || {};
    url += `?${stringify(params, { arrayFormat: 'brackets', skipNulls: true })}`;
    // 解决某些浏览器下请求报错的问题 body not allowed for get or head requests
    options.body = undefined;
  }

  return fetch(url, options)
    .then((response) => {
      if (response.status === 200) {
        return response.json()
          .then((json) => {
github rockstat / web-sdk / src / Transport.js View on Github external
Transport.prototype.makeURL = function (path, data = {}, proto = HTTPS) {
  const query = queryStringify(data);
  return `${proto}://${this.server}${this.pathPrefix}${path}?${query}`;
}
github SyneticNL / Hyral / packages / json-api / src / Request / paramsSerializer.js View on Github external
export default function paramsSerializer(parameterBag) {
  if (!parameterBag || !parameterBag.filters) {
    return '';
  }

  return stringify({
    ...serializeFilters(parameterBag),
    ...serializePaging(parameterBag),
    ...serializeSorting(parameterBag),
    ...serializeParams(parameterBag),
  });
}

qs

A querystring parser that supports nesting and arrays, with a depth limit

BSD-3-Clause
Latest version published 18 days ago

Package Health Score

94 / 100
Full package analysis