@less-is-more/less-js 1.4.11 → 1.4.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@less-is-more/less-js",
3
- "version": "1.4.11",
3
+ "version": "1.4.12",
4
4
  "description": "Fast develop kit for nodejs",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/service.js CHANGED
@@ -52,14 +52,22 @@ module.exports = class Service {
52
52
  path,
53
53
  params = {},
54
54
  async = false,
55
- asyncDelaySecond = 0
55
+ asyncDelaySecond = 0,
56
+ formFormat = true
56
57
  ) {
57
58
  let url = this.#urlPrefix.replace("SERVICE", serviceName) + path;
58
59
  try {
59
- const headers = this.setDelay(async, asyncDelaySecond);
60
- const result = await axios.post(url, qs.stringify(params), {
61
- headers,
62
- });
60
+ let headers = this.setDelay(async, asyncDelaySecond);
61
+ if (!formFormat) {
62
+ headers["Content-Type"] = "application/json";
63
+ }
64
+ const result = await axios.post(
65
+ url,
66
+ formFormat ? qs.stringify(params) : params,
67
+ {
68
+ headers,
69
+ }
70
+ );
63
71
  return result.data;
64
72
  } catch (e) {
65
73
  console.error("获取失败", url, e.message);
@@ -37,5 +37,11 @@ describe("service.js", () => {
37
37
  const result = await Service.get("supplier", "/", null, true, 2);
38
38
  console.log(result);
39
39
  });
40
+
41
+ it("json format", async () => {
42
+ const result = await Service.post("post", "/", { a: 1 }, false, 0, false);
43
+ console.log(result);
44
+ assert(result.success);
45
+ });
40
46
  });
41
47
  });