Socket
Socket
Sign inDemoInstall

rest

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rest - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

browser.js

4

bower.json
{
"name": "rest",
"version": "1.1.1",
"main": "./rest.js",
"version": "1.2.0",
"main": "./browser.js",
"moduleType": ["amd", "node"],

@@ -6,0 +6,0 @@ "dependencies": {

@@ -48,5 +48,6 @@ /*

impl.chain = function chain() {
if (console) {
(console.warn || console.log).call(console, 'rest.js: client.chain() is deprecated, use client.wrap() instead');
if (typeof console !== 'undefined') {
console.log('rest.js: client.chain() is deprecated, use client.wrap() instead');
}
return impl.wrap.apply(this, arguments);

@@ -53,0 +54,0 @@ };

@@ -61,2 +61,3 @@ /*

return client(function node(request) {
/*jshint maxcomplexity:20 */
return new responsePromise.ResponsePromise(function (resolve, reject) {

@@ -63,0 +64,0 @@

@@ -56,2 +56,3 @@ /*

return new responsePromise.ResponsePromise(function (resolve, reject) {
/*jshint maxcomplexity:20 */

@@ -97,2 +98,8 @@ var client, method, url, headers, entity, headerName, response, XMLHttpRequest;

/*jshint forin:false */
if (headerName === 'Content-Type' && headers[headerName] === 'multipart/form-data') {
// XMLHttpRequest generates its own Content-Type header with the
// appropriate multipart boundary when sending multipart/form-data.
continue;
}
client.setRequestHeader(headerName, headers[headerName]);

@@ -122,2 +129,9 @@ }

}
else {
// give the error callback a chance to fire before resolving
// requests for file:// URLs do not have a status code
setTimeout(function () {
resolve(response);
}, 0);
}
}

@@ -124,0 +138,0 @@ };

@@ -7,3 +7,2 @@ # Interceptors

- [Default Request Interceptor](#module-rest/interceptor/defaultRequest)
- [Entity Interceptor](#module-rest/interceptor/entity)
- [Hypermedia As The Engine Of Application State (HATEOAS) Interceptor](#module-rest/interceptor/hateoas)

@@ -104,3 +103,3 @@ - [Location Interceptor](#module-rest/interceptor/location)

Provide default values for the request object. Default values can be provided for the `method`, `path`, `params`, `headers` and/or `entity`. If the value does not exist in the request already, then the default value is utilized. The `method`, `path` and `entity` values are direct copies, while the `params` and `headers` values are mixed into the request. In no case will the interceptor overwrite a value in the request.
Provide default values for the request object. Default values can be provided for the `method`, `path`, `params`, `headers`, `entity`, and/or `mixin`. If the value does not exist in the request already, then the default value is utilized. The `method`, `path` and `entity` values are direct copies, while the `params`, `headers`, and `mixin` values are mixed into the request. In no case will the interceptor overwrite a value in the request.

@@ -150,2 +149,8 @@ **Phases**

</tr>
<tr>
<td>mixin</td>
<td>optional</td>
<td><em>none</em></td>
<td>default extra parameters for the <a href="clients.md#module-rest/client/xhr">XHR object</a> or <a href="clients.md#module-rest/client/node">Node.js</a>.
</tr>
</table>

@@ -179,29 +184,2 @@

<a name="module-rest/interceptor/entity"></a>
#### Entity Interceptor
`rest/interceptor/entity` ([src](../interceptor/entity.js))
Replaces the response with just the entity returned from the server. After this interceptor, the other response properties will no longer be accessible. It's best to install this interceptor as late in the chain as possible as many interceptors need access to the full response.
**Phases**
- response
**Configuration**
*none*
**Example**
```javascript
client = rest.wrap(entity);
// for a response { status: { code: 200 } }, entity: 'hello world', headers: { ... }, ... }
client().then(function (response) {
assert.same('hello world', response);
});
```
<a name="module-rest/interceptor/hateoas"></a>

@@ -298,3 +276,3 @@ #### Hypermedia As The Engine Of Application State (HATEOAS) Interceptor

Follows the `Location` header, returning the response of the subsequent request. Browsers will typically automatically follow the location header for redirect in the 300s range, however, they will not follow the Location for a response in the 200s range. Other clients may not follow 300s redirects. This interceptor will always follow a redirect for the original request.
Follows the `Location` header, returning the response of the subsequent request. Browsers will typically automatically follow the location header for redirect in the 300s range, however, they will not follow the Location for a response in the 200s range. Other clients may not follow 300s redirects. This interceptor will always follow a redirect for the original request by default. If configured with `code` the response status code has to be equal or greater than `code` the be treated as a redirect.

@@ -322,2 +300,8 @@ Subsequent redirects can be automatically followed by including this interceptor twice in the client chain. However, in this situation, redirect loops will not be detected.

</tr>
<tr>
<td>code</td>
<td>optional</td>
<td>0</td>
<td>status code if equal or greater indicates a redirect</td>
</tr>
</table>

@@ -324,0 +308,0 @@

@@ -37,5 +37,7 @@ # Content Negotiation

- application/x-www-form-urlencoded
- multipart/form-data *
These converters are loaded lazily and are located under `rest/mime/type/*`. So 'text/plain' is resolved to `rest/mime/type/text/plain`. The main MIME registry knows how to fetch these converters. Child registries extend from the main registry hierarchically and thus also get access to these provided converters.
* Multipart support is only available for requests from browsers that has implemented XMLHttpRequest 2. This includes most modern browsers with the exception of IE <=9.

@@ -42,0 +44,0 @@ <a name="mime-converters-custom"></a>

@@ -31,6 +31,1 @@ # rest.js Documentation

Declarative client configuration with wire.js.
[Dojo Toolkit](dojo.md)
Support for the Dojo Toolkit Store APIs

@@ -11,4 +11,2 @@ # wire.js

There are two aspects to the wire plugin the `rest` factory, and the `client!` reference resolver.
**TIP:** In each of these examples, `{ module: 'rest/wire' }` is loaded as it provides the 'rest' factory to the wire.js spec. Without this module being loaded into the spec, the facilities below will silently fail.

@@ -83,96 +81,1 @@

```
<a name="wire-client-resolver"></a>
### 'client!' Reference Resolver
The client! reference resolver installs several commonly used interceptors, wrapping the default client. In order, the interceptors installed are the \'errorCode', \'mime', \'entity' and \'pathPrefix'. Basic options are configurable. It is intended as a quick and dirty way to get a functional client quickly. In most cases, the \'rest' factory will be more useful.
<table>
<tr>
<th>Property</th>
<th>Required?</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<td>client</td>
<td>optional</td>
<td><em>default client</em></td>
<td>client to wrap with the configured interceptors
</tr>
<tr>
<td>errorCode</td>
<td>optional</td>
<td>400</td>
<td>response status code above which to make the response in error, provided a boolean false to block installing the <code>errorCode</code> interceptor</td>
</tr>
<tr>
<td>mime</td>
<td>optional</td>
<td>'application/x-www-form-urlencoded'</td>
<td>mime type for request entities, provided a boolean false to block installing the <code>mime</code> interceptor</td>
</tr>
<tr>
<td>accept</td>
<td>optional</td>
<td><em>mime value</em></td>
<td>accept header for the request</td>
</tr>
<tr>
<td>entity</td>
<td>optional</td>
<td><em>none</em></td>
<td>provided a boolean false to block installing the <code>entity</code> interceptor</td>
</tr>
</table>
The pathPrefix interceptor is not configured via a property, but the string after the '!'.
```javascript
client: {
{ $ref: 'client!' }
}
```
Is equivlent to:
```javascript
client = rest.wrap(errorCode, { code: 400 })
.wrap(mime, { mime: 'application/x-www-form-urlencoded' })
.wrap(entity)
.wrap(pathPrefix, { prefix: '' });
```
To disable interceptors, provide a boolean false for the config value
```javascript
client: {
{ $ref: 'client!', errorCode: false, mime: false, entity: false }
}
```
Is equivlent to:
```javascript
client = rest.wrap(pathPrefix, { prefix: '' });
```
A custom client can be used instead of the default client
```javascript
client: {
{ $ref: 'client!', client: { ref: 'someOtherClient' } }
}
```
Is equivlent to:
```javascript
client = someOtherClient.wrap(errorCode, { code: 400 })
.wrap(mime, { mime: 'application/x-www-form-urlencoded' })
.wrap(entity)
.wrap(pathPrefix, { prefix: '' });
```
A [Dojo Store](dojo.md#dojo-stores) variant of the `client!` reference resolver is available as `resource!` from [`rest/dojo/wire`](dojo.md#module-rest/dojo/wire).

@@ -15,3 +15,3 @@ /*

defaultClient = require('./rest');
defaultClient = require('./client/default');
mixin = require('./util/mixin');

@@ -18,0 +18,0 @@ responsePromise = require('./util/responsePromise');

@@ -37,3 +37,4 @@ /*

headers: mixin,
entity: copy
entity: copy,
mixin: mixin
};

@@ -55,3 +56,3 @@

*
* For 'params' and 'headers' individual values are mixed in with the
* For 'params', 'headers', and 'mixin', individual values are mixed in with the
* request's values. The result is a new object representiing the combined

@@ -63,4 +64,5 @@ * request and config values. Neither input object is mutated.

* @param {string} [config.path] the default path
* @param {Object} [config.params] the default params, mixed with the request's exsisting params
* @param {Object} [config.headers] the default headers, mixed with the request's exsisting headers
* @param {Object} [config.params] the default params, mixed with the request's existing params
* @param {Object} [config.headers] the default headers, mixed with the request's existing headers
* @param {Object} [config.mixin] the default "mixins" (http/https options), mixed with the request's existing "mixins"
*

@@ -67,0 +69,0 @@ * @returns {Client}

/*
* Copyright 2012 the original author or authors
* Copyright 2012-2014 the original author or authors
* @license MIT, see LICENSE.txt for details

@@ -17,3 +17,9 @@ *

if (typeof console !== 'undefined') {
console.log('rest.js: rest/interceptor/entity is deprecated, please use response.entity() instead');
}
/**
* @deprecated use response.entity() instead
*
* Returns the response entity as the response, discarding other response

@@ -20,0 +26,0 @@ * properties.

@@ -120,3 +120,3 @@ /*

find.findProperties(response, 'links', function (obj, host) {
find.findProperties(response.entity, 'links', function (obj, host) {
var target;

@@ -123,0 +123,0 @@

@@ -17,2 +17,7 @@ /*

function isRedirect(response, config) {
var matchesRedirectCode = config.code === 0 || (response.status && response.status.code >= config.code);
return response.headers && response.headers.Location && matchesRedirectCode;
}
/**

@@ -31,5 +36,14 @@ * Follows the Location header in a response, if present. The response

return interceptor({
init: function (config) {
config.code = config.code || 0;
return config;
},
success: function (response, config, client) {
if (response.headers && response.headers.Location) {
return (config.client || (response.request && response.request.originator) || client.skip())({
var request;
if (isRedirect(response, config)) {
request = response.request || {};
client = (config.client || request.originator || client.skip());
return client({
method: 'GET',

@@ -39,2 +53,3 @@ path: response.headers.Location

}
return response;

@@ -41,0 +56,0 @@ }

@@ -79,26 +79,10 @@ /*

function loadAMD(mime) {
var timeout;
return when.promise(function (resolve, reject) {
// HOPE reject on a local require would be nice
timeout = setTimeout(reject, 1000);
require(['./type/' + mime], resolve, reject);
}).otherwise(function (ex) {
return when.reject(ex || new Error('Timeout while loading mime module: ' + mime));
}).ensure(function () {
clearTimeout(timeout);
});
}).timeout(1000);
}
function loadNode(mime) {
return when.promise(function (resolve, reject) {
try {
resolve(require('./type/' + mime));
}
catch (e) {
reject(e);
}
});
return when.attempt(require, './type/' + mime);
}

@@ -105,0 +89,0 @@

{
"name": "rest",
"version": "1.1.1",
"version": "1.2.0",
"description": "RESTful HTTP client library",

@@ -32,2 +32,6 @@ "keywords": ["rest", "http", "client", "rest-template", "spring", "cujojs"],

"web": "http://unscriptable.com"
},
{
"name": "Michael Jackson",
"web": "https://github.com/mjackson"
}

@@ -40,14 +44,16 @@ ],

"wire": "~0.9",
"dojo": "https://github.com/dojo/dojo/tarball/1.7.2",
"test-support": "~0.3",
"test-support": "~0.4",
"curl": "https://github.com/cujojs/curl/tarball/0.7.3",
"poly": "https://github.com/cujojs/poly/tarball/0.5.1"
},
"main": "./rest",
"main": "./node",
"browser": "./browser",
"scripts": {
"test": "jshint . && buster test --node",
"ci": "npm test && sauceme -b test/browsers.json",
"test": "npm run-script lint && npm run-script buster",
"start": "buster static -e browser",
"tunnel": "sauceme -m"
"tunnel": "sauceme -m",
"lint": "jshint .",
"buster": "buster test --node",
"sauceme": "sauceme"
}
}

@@ -217,2 +217,3 @@ rest.js

- John Hann <john@unscriptable.com>
- Michael Jackson <mjijackson@gmail.com>

@@ -233,2 +234,12 @@ Please see CONTRIBUTING.md for details on how to contribute to this project.

1.2.0
- deprecated rest/interceptor/entity: instead use response.entity()
- deprecated and removed wire.js reference resolves 'client!' and 'resource!', instead use the 'rest/wire' factory
- deprecated and removed Dojo store support
- separate browser and node main modules, browser consumers should switch their main module from 'rest/rest' to 'rest/browser'. This allows tools such as browerify and webpack to more intelligently reason about the module structure.
- Multipart requests for browsers that support FormData (sorry IE 6-9). Thanks @mjackson
- mixin property support in defaultRequest interceptor. Thanks @jiangtyd
- allow location interceptor to be applied based on the status code. Thanks @phillipj
- better support for file:// URL via the XHR client
1.1.1

@@ -235,0 +246,0 @@ - support for IE 11, Safari 7 and iOS 7 (no code changes required, now actively testing)

@@ -8,119 +8,18 @@ /*

(function (define, process) {
(function (define) {
'use strict';
var undef;
define(function (require) {
/**
* Plain JS Object containing properties that represent an HTTP request.
*
* Depending on the capabilities of the underlying client, a request
* may be cancelable. If a request may be canceled, the client will add
* a canceled flag and cancel function to the request object. Canceling
* the request will put the response into an error state.
*
* @field {string} [method='GET'] HTTP method, commonly GET, POST, PUT, DELETE or HEAD
* @field {string|UrlBuilder} [path=''] path template with optional path variables
* @field {Object} [params] parameters for the path template and query string
* @field {Object} [headers] custom HTTP headers to send, in addition to the clients default headers
* @field [entity] the HTTP entity, common for POST or PUT requests
* @field {boolean} [canceled] true if the request has been canceled, set by the client
* @field {Function} [cancel] cancels the request if invoked, provided by the client
* @field {Client} [originator] the client that first handled this request, provided by the interceptor
*
* @class Request
*/
/**
* Plain JS Object containing properties that represent an HTTP response
*
* @field {Object} [request] the request object as received by the root client
* @field {Object} [raw] the underlying request object, like XmlHttpRequest in a browser
* @field {number} [status.code] status code of the response (i.e. 200, 404)
* @field {string} [status.text] status phrase of the response
* @field {Object] [headers] response headers hash of normalized name, value pairs
* @field [entity] the response body
*
* @class Response
*/
/**
* HTTP client particularly suited for RESTful operations.
*
* @field {function} wrap wraps this client with a new interceptor returning the wrapped client
*
* @param {Request} the HTTP request
* @returns {ResponsePromise<Response>} a promise the resolves to the HTTP response
*
* @class Client
*/
/**
* Extended when.js Promises/A+ promise with HTTP specific helpers
*q
* @method entity promise for the HTTP entity
* @method status promise for the HTTP status code
* @method headers promise for the HTTP response headers
* @method header promise for a specific HTTP response header
*
* @class ResponsePromise
* @extends Promise
*/
var client, target, platformDefault;
client = require('./client');
target = platformDefault = (function () {
if (process && process.versions && process.versions.node) {
// evade build tools
var moduleId = './client/node';
return require(moduleId);
}
return require('./client/xhr');
}());
/**
* Make a request with the default client
* @param {Request} the HTTP request
* @returns {Promise<Response>} a promise the resolves to the HTTP response
*/
function defaultClient() {
return target.apply(undef, arguments);
if (console) {
(console.warn || console.log).call(console, 'rest.js: The main module has moved, please switch your configuration to use \'rest/browser\' as the main module for browser applications.');
}
/**
* Change the default client
* @param {Client} client the new default client
*/
defaultClient.setDefaultClient = function setDefaultClient(client) {
target = client;
};
return require('./browser');
/**
* Obtain a direct reference to the current default client
* @returns {Client} the default client
*/
defaultClient.getDefaultClient = function getDefaultClient() {
return target;
};
/**
* Reset the default client to the platform default
*/
defaultClient.resetDefaultClient = function resetDefaultClient() {
target = platformDefault;
};
return client(defaultClient);
});
}(
typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); },
typeof process === 'undefined' ? undefined : process
typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); }
// Boilerplate for AMD and Node
));
/*
* Copyright 2012-2013 the original author or authors
* Copyright 2012-2014 the original author or authors
* @license MIT, see LICENSE.txt for details

@@ -28,3 +28,2 @@ *

'client/**/*.js',
'dojo/**/*.js',
'interceptor/**/*.js',

@@ -35,3 +34,2 @@ 'mime/**/*.js',

'node_modules/curl/**/*.js',
'node_modules/dojo/**/*.js',
'node_modules/poly/**/*.js',

@@ -38,0 +36,0 @@ 'node_modules/when/**/*.js',

@@ -23,3 +23,3 @@ /*

client = require('rest/client');
rest = require('rest');
rest = require('rest/client/default');
interceptor = require('rest/interceptor');

@@ -26,0 +26,0 @@

@@ -113,3 +113,5 @@ /*

'should return a ResponsePromise': function () {
assert(client() instanceof responsePromise.ResponsePromise);
var response = client();
response.otherwise(function () {});
assert(response instanceof responsePromise.ResponsePromise);
}

@@ -116,0 +118,0 @@ });

@@ -177,3 +177,5 @@ /*

'should return a ResponsePromise': function () {
assert(client() instanceof responsePromise.ResponsePromise);
var response = client();
response.otherwise(function () {});
assert(response instanceof responsePromise.ResponsePromise);
}

@@ -180,0 +182,0 @@ });

@@ -189,5 +189,41 @@ /*

assert(client() instanceof responsePromise.ResponsePromise);
},
'should ignore a "Content-Type: multipart/form-data" header': {
requiresSupportFor: {
spyxhr: (function () {
// some browsers (IE6) won't allow the XHR to be spied
try {
var xhr = new XMLHttpRequest();
xhr.setRequestHeader = function () {};
return true;
}
catch (e) {
return false;
}
}())
},
'': function () {
function XMLHttpRequestSpy() {
var xhr = new XMLHttpRequest();
xhr.requestHeaders = {};
var setRequestHeader = xhr.setRequestHeader;
xhr.setRequestHeader = function (header, value) {
xhr.requestHeaders[header] = value;
return setRequestHeader.apply(xhr, arguments);
};
return xhr;
}
return client({
engine: XMLHttpRequestSpy,
path: '/',
headers: { 'Content-Type': 'multipart/form-data' }
}).then(function (response) {
refute('Content-Type' in response.raw.requestHeaders);
});
}
}
});
// TODO spy XmlHttpRequest

@@ -194,0 +230,0 @@ });

/*
* Copyright 2012-2013 the original author or authors
* Copyright 2012-2014 the original author or authors
* @license MIT, see LICENSE.txt for details

@@ -13,5 +13,4 @@ *

packages: [
{ name: 'rest', location: './', main: 'rest' },
{ name: 'rest', location: './', main: 'browser' },
{ name: 'curl', location: 'node_modules/curl/src/curl', main: 'curl' },
{ name: 'dojo', location: 'node_modules/dojo', main: 'dojo' },
{ name: 'poly', location: 'node_modules/poly', main: 'poly' },

@@ -18,0 +17,0 @@ { name: 'when', location: 'node_modules/when', main: 'when' },

@@ -148,3 +148,5 @@ /*

body = { links: [ { rel: 'self', href: '/resource' } ]};
client = hateoas(function () { return { entity: body }; });
client = hateoas(function (request) {
return request.path ? { entity: body } : { entity: {} };
});

@@ -151,0 +153,0 @@ return client().then(function (response) {

@@ -47,2 +47,23 @@ /*

},
'should follow the location header when status code is greater or equal to configured status code': function () {
var client, spy;
spy = this.spy(function (request) {
var statusCode = 300;
var response = {
request: request,
headers: { },
status: { code: statusCode }
};
if (spy.callCount === 1) {
response.headers.Location = '/foo';
}
statusCode = statusCode - 1;
return response;
});
client = location(spy, { code: 300 });
return client({}).then(function () {
assert.same(2, spy.callCount);
assert.same(spy.args[1][0].path, '/foo');
}).otherwise(fail);
},
'should return the response if there is no location header': function () {

@@ -49,0 +70,0 @@ var client, spy;

@@ -27,102 +27,2 @@ /*

buster.testCase('rest/wire', {
'should use default client! config': function () {
var spec, client;
client = function (request) {
return { request: request, status: { code: 200 }, headers: { 'Content-Type': 'application/json' }, entity: '{"foo":"bar"}' };
};
spec = {
client: { $ref: 'client!', client: client },
$plugins: [{ module: 'rest/wire' }]
};
return wire(spec, { require: require }).then(function (spec) {
return spec.client({}).then(function (response) {
assert.equals('bar', response.foo);
});
}).otherwise(fail);
},
'should use client! config with entity interceptor disabled': function () {
var spec, client;
client = function (request) {
return { request: request, status: { code: 200 }, headers: { 'Content-Type': 'application/json' }, entity: '{"foo":"bar"}' };
};
spec = {
client: { $ref: 'client!path', client: client, accept: 'text/plain', entity: false },
$plugins: [{ module: 'rest/wire' }]
};
return wire(spec, { require: require }).then(function (spec) {
return spec.client({ path: 'to/somewhere' }).then(function (response) {
assert.equals('path/to/somewhere', response.request.path);
assert.equals('text/plain', response.request.headers.Accept);
assert.equals('bar', response.entity.foo);
});
}).otherwise(fail);
},
'should be rejected for a server error status code': function () {
var spec, client;
client = function (request) {
return { request: request, status: { code: 500 }, headers: { 'Content-Type': 'application/json' }, entity: '{"foo":"bar"}' };
};
spec = {
client: { $ref: 'client!', client: client },
$plugins: [{ module: 'rest/wire' }]
};
return wire(spec, { require: require }).then(
function (spec) {
return spec.client({}).then(
fail,
failOnThrow(function (response) {
assert.equals('bar', response.foo);
})
);
},
fail
);
},
'should ignore status code when errorCode interceptor is disabled': function () {
var spec, client;
client = function (request) {
return { request: request, status: { code: 500 }, headers: { 'Content-Type': 'application/json' }, entity: '{"foo":"bar"}' };
};
spec = {
client: { $ref: 'client!', client: client, errorCode: false },
$plugins: [{ module: 'rest/wire' }]
};
return wire(spec, { require: require }).then(function (spec) {
return spec.client({}).then(function (response) {
assert.equals('bar', response.foo);
});
}).otherwise(fail);
},
'should ignore Content-Type and entity when mime interceptor is disabled': function () {
var spec, client;
client = function (request) {
return { request: request, status: { code: 200 }, headers: { 'Content-Type': 'application/json' }, entity: '{"foo":"bar"}' };
};
spec = {
client: { $ref: 'client!', client: client, mime: false },
$plugins: [{ module: 'rest/wire' }]
};
return wire(spec, { require: require }).then(function (spec) {
return spec.client({}).then(function (response) {
assert.isString(response);
});
}).otherwise(fail);
},
'should use x-www-form-urlencoded as the default Content-Type for POSTs': function () {
var spec, client;
client = function (request) {
return { request: request, status: { code: 200 }, headers: { 'Content-Type': 'application/json' }, entity: '{"foo":"bar"}' };
};
spec = {
client: { $ref: 'client!', client: client, entity: false },
$plugins: [{ module: 'rest/wire' }]
};
return wire(spec, { require: require }).then(function (spec) {
return spec.client({ method: 'post', entity: { bleep: 'bloop' } }).then(function (response) {
assert.equals('bleep=bloop', response.request.entity);
assert.equals(0, response.request.headers.Accept.indexOf('application/x-www-form-urlencoded'));
assert.equals('application/x-www-form-urlencoded', response.request.headers['Content-Type']);
});
}).otherwise(fail);
},
'should use the rest factory': {

@@ -129,0 +29,0 @@ '': function () {

@@ -183,2 +183,3 @@ /*

parts: function () {
/*jshint maxcomplexity:20 */
var url, parts;

@@ -185,0 +186,0 @@ url = this.fullyQualify().build().match(urlRE);

/*
* Copyright 2012-2013 the original author or authors
* Copyright 2012-2014 the original author or authors
* @license MIT, see LICENSE.txt for details

@@ -13,62 +13,8 @@ *

var client, errorCode, mime, entity, pathPrefix, when, pipeline, plugin;
var client, when, pipeline, plugin;
client = require('../rest');
errorCode = require('./interceptor/errorCode');
mime = require('./interceptor/mime');
entity = require('./interceptor/entity');
pathPrefix = require('./interceptor/pathPrefix');
client = require('./client/default');
when = require('when');
pipeline = require('when/pipeline');
function parseConfig(name, refObj) {
return {
prefix: name,
mime: refObj.mime,
accept: refObj.accept,
errorCode: refObj.errorCode,
entity: refObj.entity
};
}
/**
* Builds the rest client for the provided config
*
* @param client the client to wrap
* @param config configuration for client interceptors
*/
function buildClient(client, config) {
return when(client, function (client) {
if (config.errorCode !== false) {
client = errorCode(client, { code: config.errorCode });
}
if (config.mime !== false) {
client = mime(client, { mime: config.mime || 'application/x-www-form-urlencoded', accept: config.accept });
}
if (config.entity !== false) {
client = entity(client);
}
client = pathPrefix(client, { prefix: config.prefix });
return client;
});
}
/**
* Resolves a 'rest' client for the specified path and scopes, e.g. client!url/to/resource
*
* @param resolver
* @param name
* @param refObj
* @param wire
*/
function resolveClient(resolver, name, refObj /*, wire */) {
var config, client;
config = parseConfig(name, refObj);
client = buildClient(refObj.client, config);
when(client, resolver.resolve, resolver.reject);
}
function normalizeRestFactoryConfig(spec, wire) {

@@ -113,3 +59,5 @@ var config = {};

resolvers: {
client: resolveClient
client: function () {
throw new Error('rest.js: client! wire reference resolved is deprecated, use \'rest\' facotry instead');
}
},

@@ -116,0 +64,0 @@ factories: {

Sorry, the diff of this file is not supported yet

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