Comparing version 1.6.0 to 2.0.0
14
index.js
@@ -9,10 +9,10 @@ const http = require('http'); | ||
const headers = options.headers || {}; | ||
if (options.data != null) { | ||
if (typeof options.data !== 'string') { | ||
if (options.body != null) { | ||
if (typeof options.body !== 'string') { | ||
return callback(new ErrorWithObject({ | ||
message: 'You did not set the data property to an String. Did you mean to JSON.stringify an object it or use the callarest.json shortcut?', | ||
code: 'SENT_OBJECT_AS_DATA' | ||
message: 'You did not set the body property to an String. Did you mean to JSON.stringify an object it or use the callarest.json shortcut?', | ||
code: 'SENT_OBJECT_AS_BODY' | ||
})); | ||
} | ||
headers['Content-Length'] = Buffer.byteLength(options.data); | ||
headers['Content-Length'] = Buffer.byteLength(options.body); | ||
} | ||
@@ -53,4 +53,4 @@ | ||
if (options.data) { | ||
request.write(options.data); | ||
if (options.body) { | ||
request.write(options.body); | ||
} | ||
@@ -57,0 +57,0 @@ request.end(); |
@@ -10,5 +10,5 @@ const ErrorWithObject = require('error-with-object'); | ||
let data; | ||
if (options.data != null) { | ||
data = JSON.stringify(options.data); | ||
let body; | ||
if (options.body != null) { | ||
body = JSON.stringify(options.body); | ||
} | ||
@@ -19,3 +19,3 @@ | ||
headers, | ||
data | ||
body | ||
}, function (error, rest) { | ||
@@ -22,0 +22,0 @@ if (error) { |
{ | ||
"name": "callarest", | ||
"version": "1.6.0", | ||
"version": "2.0.0", | ||
"keywords": [ | ||
@@ -28,9 +28,9 @@ "rest", | ||
"devDependencies": { | ||
"tape": "^4.11.0", | ||
"c8": "^6.0.1", | ||
"tape": "^4.13.2", | ||
"righto": "^6.0.1" | ||
}, | ||
"dependencies": { | ||
"c8": "^6.0.1", | ||
"error-with-object": "^1.1.0" | ||
} | ||
} |
@@ -13,6 +13,6 @@ # Callarest | ||
```javascript | ||
const callarestJson = require('callarest/json') | ||
callarestJson({ | ||
const callarest = require('callarest') | ||
callarest({ | ||
method: 'post', | ||
data: JSON.stringify({ hello: 'world' }), | ||
body: JSON.stringify({ hello: 'world' }), | ||
headers: { | ||
@@ -39,3 +39,3 @@ 'Content-Type': 'application/json' | ||
method: 'post', | ||
data: { hello: 'world' }, | ||
body: { hello: 'world' }, | ||
url: 'https://www.example.com' | ||
@@ -42,0 +42,0 @@ }, function (error, rest) { |
@@ -81,3 +81,3 @@ const test = require('tape'); | ||
url: 'http://localhost:8000/echo', | ||
data: { b: 1 } | ||
body: { b: 1 } | ||
}, righto.after(server)); | ||
@@ -94,3 +94,3 @@ | ||
test('post -> send object as data', t => { | ||
test('post -> send object as body', t => { | ||
t.plan(1); | ||
@@ -102,3 +102,3 @@ | ||
url: 'http://localhost:8000/echo', | ||
data: 'something' | ||
body: 'something' | ||
}, righto.after(server)); | ||
@@ -105,0 +105,0 @@ |
@@ -60,3 +60,3 @@ const test = require('tape'); | ||
url: 'http://localhost:8000/echo', | ||
data: 'hello' | ||
body: 'hello' | ||
}, righto.after(server)); | ||
@@ -73,3 +73,3 @@ | ||
test('post -> send object as data', t => { | ||
test('post -> send object as body', t => { | ||
t.plan(1); | ||
@@ -81,3 +81,3 @@ | ||
url: 'http://localhost:8000/echo', | ||
data: { | ||
body: { | ||
a: 1 | ||
@@ -88,3 +88,3 @@ } | ||
request(function (error, result) { | ||
t.equal(error.code, 'SENT_OBJECT_AS_DATA'); | ||
t.equal(error.code, 'SENT_OBJECT_AS_BODY'); | ||
@@ -91,0 +91,0 @@ destroyServer(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
12381
3
- Removedc8@^6.0.1
- Removed@bcoe/v8-coverage@0.2.3(transitive)
- Removed@types/is-windows@0.2.0(transitive)
- Removed@types/istanbul-lib-coverage@2.0.6(transitive)
- Removedansi-regex@4.1.1(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedc8@6.0.1(transitive)
- Removedcamelcase@5.3.1(transitive)
- Removedcliui@5.0.0(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedconvert-source-map@1.9.0(transitive)
- Removedcross-spawn@7.0.3(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removedemoji-regex@7.0.3(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedfind-up@3.0.04.1.0(transitive)
- Removedforeground-child@2.0.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedfuri@1.3.0(transitive)
- Removedget-caller-file@2.0.5(transitive)
- Removedglob@7.2.3(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedhtml-escaper@2.0.2(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedis-fullwidth-code-point@2.0.0(transitive)
- Removedis-windows@1.0.2(transitive)
- Removedisexe@2.0.0(transitive)
- Removedistanbul-lib-coverage@2.0.5(transitive)
- Removedistanbul-lib-report@2.0.8(transitive)
- Removedistanbul-reports@2.2.7(transitive)
- Removedjson-parse-better-errors@1.0.2(transitive)
- Removedload-json-file@4.0.0(transitive)
- Removedlocate-path@3.0.05.0.0(transitive)
- Removedmake-dir@2.1.0(transitive)
- Removedminimatch@3.1.2(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removedonce@1.4.0(transitive)
- Removedp-limit@2.3.0(transitive)
- Removedp-locate@3.0.04.1.0(transitive)
- Removedp-try@2.2.0(transitive)
- Removedparse-json@4.0.0(transitive)
- Removedpath-exists@3.0.04.0.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpath-key@3.1.1(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpath-type@3.0.0(transitive)
- Removedpify@3.0.04.0.1(transitive)
- Removedread-pkg@3.0.0(transitive)
- Removedread-pkg-up@4.0.0(transitive)
- Removedrequire-directory@2.1.1(transitive)
- Removedrequire-main-filename@2.0.0(transitive)
- Removedresolve@1.22.8(transitive)
- Removedrimraf@3.0.2(transitive)
- Removedsemver@5.7.2(transitive)
- Removedset-blocking@2.0.0(transitive)
- Removedshebang-command@2.0.0(transitive)
- Removedshebang-regex@3.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedsource-map@0.7.4(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.20(transitive)
- Removedstring-width@3.1.0(transitive)
- Removedstrip-ansi@5.2.0(transitive)
- Removedstrip-bom@3.0.0(transitive)
- Removedsupports-color@6.1.0(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedtest-exclude@5.2.3(transitive)
- Removedv8-to-istanbul@3.2.6(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)
- Removedwhich@2.0.2(transitive)
- Removedwhich-module@2.0.1(transitive)
- Removedwrap-ansi@5.1.0(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedy18n@4.0.3(transitive)
- Removedyargs@14.2.3(transitive)
- Removedyargs-parser@15.0.3(transitive)