Comparing version 0.7.5 to 0.8.0
@@ -22,3 +22,5 @@ var parser, http, https, when, UrlBuilder, normalizeHeaderName, httpsExp; | ||
options = parser.parse(url); | ||
options.method = request.method || 'GET'; | ||
entity = request.entity; | ||
request.method = request.method || entity ? 'POST' : 'GET'; | ||
options.method = request.method; | ||
headers = options.headers = {}; | ||
@@ -28,3 +30,2 @@ Object.keys(request.headers || {}).forEach(function (name) { | ||
}); | ||
entity = request.entity; | ||
if (!headers['Content-Length']) { | ||
@@ -31,0 +32,0 @@ headers['Content-Length'] = entity ? Buffer.byteLength(entity, 'utf8') : 0; |
@@ -49,3 +49,5 @@ (function (XMLHttpRequest, define) { | ||
method = request.method || 'GET'; | ||
entity = request.entity; | ||
request.method = request.method || entity ? 'POST' : 'GET'; | ||
method = request.method; | ||
url = new UrlBuilder(request.path || '', request.params).build(); | ||
@@ -77,3 +79,2 @@ client.open(method, url, true); | ||
entity = request.entity; | ||
client.send(entity); | ||
@@ -80,0 +81,0 @@ } |
(function (define) { | ||
define(['./_base', '../util/base64'], function (base, base64) { | ||
define(['../interceptor', '../util/base64'], function (interceptor, base64) { | ||
"use strict"; | ||
@@ -15,3 +15,3 @@ | ||
*/ | ||
return base({ | ||
return interceptor({ | ||
request: function handleRequest(request, config) { | ||
@@ -18,0 +18,0 @@ var headers, username, password; |
(function (define) { | ||
define(['./_base'], function (base) { | ||
define(['../interceptor'], function (interceptor) { | ||
"use strict"; | ||
@@ -14,3 +14,3 @@ | ||
*/ | ||
return base({ | ||
return interceptor({ | ||
response: function (response) { | ||
@@ -17,0 +17,0 @@ if ('entity' in response) { |
(function (define) { | ||
define(['./_base', 'when'], function (base, when) { | ||
define(['../interceptor', 'when'], function (interceptor, when) { | ||
"use strict"; | ||
@@ -17,3 +17,3 @@ | ||
*/ | ||
return base({ | ||
return interceptor({ | ||
response: function (response, config) { | ||
@@ -20,0 +20,0 @@ var code = config.code || 400; |
(function (define) { | ||
define(['../client/jsonp'], function (defaultClient) { | ||
define(['../interceptor', '../client/jsonp'], function (interceptor, jsonpClient) { | ||
"use strict"; | ||
@@ -21,27 +21,13 @@ | ||
*/ | ||
return function (client, config) { | ||
var interceptor; | ||
if (typeof client === 'object') { | ||
config = client; | ||
} | ||
if (typeof client !== 'function') { | ||
client = defaultClient; | ||
} | ||
config = config || {}; | ||
config.callback = config.callback || {}; | ||
interceptor = function (request) { | ||
return interceptor({ | ||
client: jsonpClient, | ||
request: function (request, config) { | ||
config.callback = config.callback || {}; | ||
request.callback = request.callback || {}; | ||
request.callback.param = request.callback.param || config.callback.param; | ||
request.callback.prefix = request.callback.prefix || config.callback.prefix; | ||
return client(request); | ||
}; | ||
interceptor.skip = function () { | ||
return client; | ||
}; | ||
return request; | ||
} | ||
}); | ||
return interceptor; | ||
}; | ||
}); | ||
@@ -48,0 +34,0 @@ |
(function (define) { | ||
define(['./_base', '../mime/registry', 'when'], function (base, registry, when) { | ||
define(['../interceptor', '../mime/registry', 'when'], function (interceptor, registry, when) { | ||
"use strict"; | ||
@@ -20,3 +20,3 @@ | ||
*/ | ||
return base({ | ||
return interceptor({ | ||
request: function (request, config) { | ||
@@ -23,0 +23,0 @@ var mime, headers, serializer, requestReady; |
(function (define) { | ||
define(['./_base'], function (base) { | ||
define(['../interceptor'], function (interceptor) { | ||
"use strict"; | ||
@@ -22,3 +22,3 @@ | ||
*/ | ||
return base({ | ||
return interceptor({ | ||
request: function (request, config) { | ||
@@ -25,0 +25,0 @@ var path; |
{ | ||
"name": "rest", | ||
"version": "0.7.5", | ||
"version": "0.8.0", | ||
"description": "HTTP client library inspired by the Spring Framework's RestTemplate", | ||
@@ -5,0 +5,0 @@ "keywords": ["rest", "http", "client", "rest-template", "spring"], |
@@ -23,3 +23,3 @@ Rest Template | ||
$ npm install rest-template | ||
$ npm install rest | ||
@@ -163,3 +163,12 @@ From source: | ||
0.8.0 | ||
- npm name change 'rest-template' -> 'rest' | ||
- introduced experimental HATEOAS support | ||
- introduced 'location' interceptor which follows Location response headers, issuing a GET for the specified URL | ||
- default method to POST when request contains an entity | ||
- response handlers now have access to the request client to issue subsequent requests | ||
- interceptors may specify their default client | ||
- renamed `rest/interceptor/_base` to `rest/interceptor` | ||
0.7.5 | ||
- Initial release, everything is new |
@@ -43,2 +43,3 @@ var buster, rest, client, server, assert, refute; | ||
assert.same(request, response.request); | ||
assert.equals(response.request.method, 'GET'); | ||
assert.equals(response.entity, 'hello world'); | ||
@@ -53,3 +54,3 @@ assert.equals(response.status.code, 200); | ||
'should make a POST with an entity': function (done) { | ||
var request = { path: 'http://localhost:8080/', method: 'POST', entity: 'echo' }; | ||
var request = { path: 'http://localhost:8080/', entity: 'echo' }; | ||
client(request).then( | ||
@@ -59,2 +60,3 @@ function (response) { | ||
assert.same(request, response.request); | ||
assert.equals(response.request.method, 'POST'); | ||
assert.equals(response.entity, 'echo'); | ||
@@ -61,0 +63,0 @@ assert.equals(response.status.code, 200); |
@@ -25,2 +25,3 @@ (function (buster, define) { | ||
assert.same(request, response.request); | ||
assert.equals(response.request.method, 'GET'); | ||
assert.equals(xhr.responseText, response.entity); | ||
@@ -36,3 +37,3 @@ assert.equals(xhr.status, response.status.code); | ||
'should make a POST with an entity': function (done) { | ||
var request = { path: '/', method: 'post', entity: 'hello world' }; | ||
var request = { path: '/', entity: 'hello world' }; | ||
xhr(request).then( | ||
@@ -43,2 +44,3 @@ function (response) { | ||
assert.same(request, response.request); | ||
assert.equals(response.request.method, 'POST'); | ||
assert.equals(xhr.responseText, response.entity); | ||
@@ -45,0 +47,0 @@ assert.equals(xhr.status, response.status.code); |
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
116838
62
3166
173