Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rest-facade

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rest-facade - npm Package Compare versions

Comparing version 1.15.0 to 1.16.0

2

package.json
{
"name": "rest-facade",
"version": "1.15.0",
"version": "1.16.0",
"description": "Simple abstraction for consuming REST API endpoints",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -312,1 +312,13 @@ # rest-facade [![Build Status](https://travis-ci.org/ngonzalvez/rest-facade.svg?branch=master)](https://travis-ci.org/ngonzalvez/rest-facade)

```
### Specifying the type of the request body
By default the request body type is 'json' but you can specify a custom type as follows:
```js
var client = new rest.Client(url, {
request: {
type: 'form'
}
});
```
Valid values are: **json** and **form**.

@@ -129,4 +129,4 @@ var extend = require('util')._extend;

if (typeof data !== 'object') {
throw new ArgumentError('Missing data object');
if (typeof data !== 'object' && typeof data !== 'string') {
throw new ArgumentError('The data must be an object or a serialized json');
}

@@ -169,4 +169,4 @@

if (typeof data !== 'object') {
throw new ArgumentError('The data must be an object');
if (typeof data !== 'object' && typeof data !== 'string') {
throw new ArgumentError('The data must be an object or a serialized json');
}

@@ -195,4 +195,4 @@

if (typeof data !== 'object') {
throw new ArgumentError('The data must be an object');
if (typeof data !== 'object' && typeof data !== 'string') {
throw new ArgumentError('The data must be an object or a serialized json');
}

@@ -289,2 +289,3 @@

var responseCase = this.options.response.body.convertCase;
var reqType = this.options.request.type || 'json';
var queryParams = {};

@@ -322,3 +323,3 @@ var convertCaseParams = paramsCase ? changeCase[paramsCase] : null;

if (convertCaseBody) {
if (convertCaseBody && typeof options.data === 'object') {
for (var key in options.data) {

@@ -338,2 +339,4 @@ if (options.data.hasOwnProperty(key)) {

req = req.type(reqType);
if (proxy) {

@@ -340,0 +343,0 @@ req = req.proxy(proxy);

@@ -35,4 +35,5 @@ var extend = require('util')._extend;

expect(client).to.not.throw(ArgumentError);
}
},
},

@@ -275,3 +276,3 @@ '#getAll': {

expect(this.client.post)
.to.throw(ArgumentError, 'Missing data object');
.to.throw(ArgumentError, 'The data must be an object or a serialized json');
},

@@ -382,3 +383,3 @@

expect(updateWithoutData).to.throw(ArgumentError, 'The data must be an object');
expect(updateWithoutData).to.throw(ArgumentError, 'The data must be an object or a serialized json');
},

@@ -479,3 +480,3 @@

expect(updateWithoutData).to.throw(ArgumentError, 'The data must be an object');
expect(updateWithoutData).to.throw(ArgumentError, 'The data must be an object or a serialized json');
},

@@ -791,4 +792,38 @@

},
}
'should use the request type when defined':
async function (done) {
// JSON Request type.
var jsonClient = new Client(domain + endpoint);
var jsonRequest = nock(domain)
.matchHeader('content-type', 'application/json')
.get(endpoint)
.reply(200);
await jsonClient.get();
expect(jsonRequest.isDone()).to.be.true;
// Form request type.
var formClient = new Client(domain + endpoint, { request: { type: 'form' }});
var formRequest = nock( domain)
.matchHeader('Content-Type', 'application/x-www-form-urlencoded')
.get(endpoint)
.reply(200);
await formClient.get()
expect(formRequest.isDone()).to.be.true;
done();
},
},
'allow serialized request data':
function(done) {
var expected = { firstName: 'John', lastName: 'Doe' };
var client = new Client(domain + endpoint);
var request = nock(domain).post(endpoint, expected).reply(200);
client.post(JSON.stringify(expected), function () {
expect(request.isDone()).to.be.true;
done();
});
},
}
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc