Socket
Socket
Sign inDemoInstall

rest

Package Overview
Dependencies
Maintainers
2
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.0.0 to 1.0.1

test/rest-test.js

2

bower.json
{
"name": "rest",
"version": "1.0.0",
"version": "1.0.1",
"main": "./rest.js",

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

@@ -9,3 +9,3 @@ /*

(function (define) {
(function (define, envRequire) {
'use strict';

@@ -17,5 +17,5 @@

parser = require('url');
http = require('http');
https = require('https');
parser = envRequire('url');
http = envRequire('http');
https = envRequire('https');
when = require('when');

@@ -147,4 +147,5 @@ UrlBuilder = require('../UrlBuilder');

}(
typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); }
typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); },
typeof require === 'function' && require
// Boilerplate for AMD and Node
));

@@ -35,5 +35,9 @@ # Clients

The default client is also the main module for the rest.js package. It's not a client implementations, but an alias to the best client for a platform. When running within a browser, the XHR client is used; when running within Node.js, the Node client is used. As other JavaScript environments are supported, the default client will continue to map directly to the most appropriate client implementation.
The default client is also the main module for the rest.js package. It's not a client implementation, but an alias to the best client for a platform. When running within a browser, the XHR client is used; when running within Node.js, the Node client is used. As other JavaScript environments are supported, the default client will continue to map directly to the most appropriate client implementation.
The default client is used internally when no custom client is configured. There are times, when it's useful to change the default client; such as when the automatic environment sniffing is wrong, or you want to add support for a new environment that rest.js doesn't yet understand. In these cases, you can set, get and reset the default client using the `rest.setDefaultClient(client)`, `rest.getDefaultClient()` and `rest.resetDefaultClient()` methods respectively.
While it may be tempting to change the default client for application level concerns, changing the default will impact all consumers. In just about every case, using an [Interceptor](./interceptors.md) is preferred.
<a name="module-rest/client/xhr"></a>

@@ -40,0 +44,0 @@ ### XMLHttpReqest Client

@@ -62,7 +62,13 @@ /*

var client = config.client || request.originator;
request.entity = serializer.write(request.entity, { client: client, request: request });
requestReady.resolve(request);
try {
request.entity = serializer.write(request.entity, { client: client, request: request });
requestReady.resolve(request);
}
catch (e) {
// TODO include cause of the error, see #45
requestReady.reject('mime-serialization');
}
},
function () {
requestReady.reject('unknown-mime');
requestReady.reject('mime-unknown');
}

@@ -86,4 +92,11 @@ );

var client = config.client || response.request && response.request.originator;
response.entity = serializer.read(response.entity, { client: client, response: response });
responseReady.resolve(response);
try {
response.entity = serializer.read(response.entity, { client: client, response: response });
responseReady.resolve(response);
}
catch (e) {
response.error = 'mime-deserialization';
response.cause = e;
responseReady.reject(response);
}
});

@@ -90,0 +103,0 @@

@@ -24,7 +24,7 @@ Copyright (c) 2012-2013 the original author or authors

Code published by Scott Andrews or Jeremy Grelle is copyright VMware and
licensed under the above terms.
Code published by Scott Andrews or Jeremy Grelle prior to 2013-09-21 is
copyright Pivotal and licensed under the above terms.
VMware, Inc.
3401 Hillview Avenue
Palo Alto, CA 94304
GoPivotal, Inc.
1900 South Norfolk Street, Suite 125
San Mateo, CA 94403
{
"name": "rest",
"version": "1.0.0",
"version": "1.0.1",
"description": "RESTful HTTP client library",

@@ -20,3 +20,3 @@ "keywords": ["rest", "http", "client", "rest-template", "spring", "cujojs"],

"name": "Scott Andrews",
"email": "sandrews@gopivotal.com",
"email": "scothis@gmail.com",
"web": "http://twitter.com/scothis"

@@ -28,3 +28,7 @@ }

"name": "Jeremy Grelle",
"email": "jgrelle@gopivotal.com"
"email": "jeremy.grelle@gmail.com"
},
{
"name": "John Hann",
"web": "http://unscriptable.com"
}

@@ -31,0 +35,0 @@ ],

@@ -214,4 +214,5 @@ rest.js

- Scott Andrews <sandrews@gopivotal.com>
- Jeremy Grelle <jgrelle@gopivotal.com>
- Scott Andrews <scothis@gmail.com>
- Jeremy Grelle <jeremy.grelle@gmail.com>
- John Hann <john@unscriptable.com>

@@ -224,3 +225,3 @@ Please see CONTRIBUTING.md for details on how to contribute to this project.

Copyright 2012-2013 the original author or authors
Copyright 2012-2014 the original author or authors

@@ -233,2 +234,7 @@ rest.js is made available under the MIT license. See LICENSE.txt for details.

1.0.1
- handle exceptions thrown from MIME converters
- allow overriding the default client
- allow AMD loaders to load node client. Useful when using an AMD loader with Node
1.0.0

@@ -235,0 +241,0 @@ - JSON HAL mime serializer for application/hal+json

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

@@ -11,6 +11,6 @@ *

var undef;
define(function (require) {
var moduleId;
/**

@@ -60,9 +60,48 @@ * Plain JS Object containing properties that represent an HTTP request.

if (process && process.versions && process.versions.node) {
// evade build tools
moduleId = './client/node';
return require(moduleId);
var client, platformDefault;
client = 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 client.apply(undef, arguments);
}
return require('./client/xhr');
/**
* Change the default client
* @param {Client} client the new default client
*/
defaultClient.setDefaultClient = function setDefaultClient(c) {
client = c;
};
/**
* Obtain a direct reference to the current default client
* @returns {Client} the default client
*/
defaultClient.getDefaultClient = function getDefaultClient() {
return client;
};
/**
* Reset the default client to the platform default
*/
defaultClient.resetDefaultClient = function resetDefaultClient() {
client = platformDefault;
};
return defaultClient;
});

@@ -69,0 +108,0 @@

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

@@ -105,3 +105,4 @@ *

'should not be the default client': function () {
refute.same(client, rest);
rest.resetDefaultClient();
refute.same(client, rest.getDefaultClient());
},

@@ -108,0 +109,0 @@ 'should support interceptor chaining': function () {

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

@@ -139,3 +139,4 @@ *

'should be the default client': function () {
assert.same(client, rest);
rest.resetDefaultClient();
assert.same(client, rest.getDefaultClient());
},

@@ -142,0 +143,0 @@ 'should support interceptor chaining': function () {

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

@@ -112,3 +112,4 @@ *

'should not be the default client': function () {
refute.same(client, rest);
rest.resetDefaultClient();
refute.same(client, rest.getDefaultClient());
},

@@ -115,0 +116,0 @@ 'should support interceptor chaining': function () {

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

@@ -180,3 +180,4 @@ *

'should be the default client': function () {
assert.same(xhr, rest);
rest.resetDefaultClient();
assert.same(xhr, rest.getDefaultClient());
},

@@ -183,0 +184,0 @@ 'should support interceptor chaining': function () {

@@ -93,3 +93,3 @@ /*

failOnThrow(function (response) {
assert.same('unknown-mime', response.error);
assert.same('mime-unknown', response.error);
assert.same(request, response.request);

@@ -142,2 +142,54 @@ })

},
'should reject the response if the serializer fails to write the request': function () {
var client, converter, customRegistry;
converter = {
read: function (str) {
throw str;
}
};
customRegistry = registry.child();
customRegistry.register('application/vnd.com.example', converter);
client = mime(
function (request) {
return { request: request };
},
{ mime: 'application/vnd.com.example', registry: customRegistry }
);
return client({ entity: 'request entity' }).then(
fail,
failOnThrow(function (response) {
assert.equals(response.error, 'mime-serialization');
})
);
},
'should reject the response if the serializer fails to read the response': function () {
var client, converter, customRegistry;
converter = {
write: function (obj) {
throw obj;
}
};
customRegistry = registry.child();
customRegistry.register('application/vnd.com.example', converter);
client = mime(
function (request) {
return { request: request, headers: { 'Content-Type': 'application/vnd.com.example' }, entity: 'response entity' };
},
{ registry: customRegistry }
);
return client({}).then(
fail,
failOnThrow(function (response) {
assert.equals(response.error, 'mime-deserialization');
})
);
},
'should have the default client as the parent by default': function () {

@@ -144,0 +196,0 @@ assert.same(rest, mime().skip());

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