function serializeRequest(req = {}) {
  const { url = '', query, form } = req;
  const joinSearch = (...strs) => {
    const search = strs.filter((a) => a).join('&'); // Only truthy value
    return search ? `?${search}` : ''; // Only add '?' if there is a str
  };

  if (form) {
    const hasFile = Object.keys(form).some((key) => {
      const { value } = form[key];
      return isFile(value) || isArrayOfFile(value);
    });

    const contentType = req.headers['content-type'] || req.headers['Content-Type'];

    if (hasFile || /multipart\/form-data/i.test(contentType)) {
      const formdata = buildFormData(req.form);
      req.formdata = formdata;
      req.body = formdata;
    } else {
      req.body = encodeFormOrQuery(form);
    }

    delete req.form;
  }

  if (query) {
    const [baseUrl, oriSearch] = url.split('?');
    let newStr = '';

    if (oriSearch) {
      const oriQuery = new URLSearchParams(oriSearch);
      const keysToRemove = Object.keys(query);
      keysToRemove.forEach((key) => oriQuery.delete(key));
      newStr = String(oriQuery);
    }

    const finalStr = joinSearch(newStr, encodeFormOrQuery(query));
    req.url = baseUrl + finalStr;
    delete req.query;
  }
  return req;
}
Encode parameter names and values
@param {Object} result - parameter names and values
@param {string} parameterName - Parameter name
@return {object} encoded parameter names and values