Skip to content

Commit

Permalink
(inc) minor version
Browse files Browse the repository at this point in the history
(feature) Allow headers to be passed in inter-service http requests #17
  • Loading branch information
jstty committed Nov 15, 2016
1 parent 4ab9318 commit 6bb904c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
21 changes: 11 additions & 10 deletions legacy/router.service.adapter.http.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ ServiceHTTPAdapter.prototype._buildURI = function (path, data) {
return url.format(uri);
};

ServiceHTTPAdapter.prototype._request = function (method, path, data, body) {
ServiceHTTPAdapter.prototype._request = function (method, path, data, body, headers) {
// add promise wrapper
return when.promise(function (resolve, reject) {
// ------------------------------------------------
request({
method: method,
uri: this._buildURI(path, data),
body: body,
json: _.isObject(body)
json: _.isObject(body),
headers: headers || {}
}, function (error, response, body) {
if (error) {
reject(error);
Expand Down Expand Up @@ -87,15 +88,15 @@ ServiceHTTPAdapter.prototype._request = function (method, path, data, body) {
/* ---------------------------------------------------
* Public Functions
* --------------------------------------------------- */
ServiceHTTPAdapter.prototype.get = function (path, data) {
return this._request('GET', path, data);
ServiceHTTPAdapter.prototype.get = function (path, data, headers) {
return this._request('GET', path, data, null, headers);
};
ServiceHTTPAdapter.prototype.post = function (path, body) {
return this._request('POST', path, null, body);
ServiceHTTPAdapter.prototype.post = function (path, body, headers) {
return this._request('POST', path, null, body, headers);
};
ServiceHTTPAdapter.prototype.put = function (path, body) {
return this._request('PUT', path, null, body);
ServiceHTTPAdapter.prototype.put = function (path, body, headers) {
return this._request('PUT', path, null, body, headers);
};
ServiceHTTPAdapter.prototype.delete = function (path, data) {
return this._request('DELETE', path, data);
ServiceHTTPAdapter.prototype.delete = function (path, data, headers) {
return this._request('DELETE', path, data, null, headers);
};
27 changes: 14 additions & 13 deletions lib/router.service.adapter.http.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ ServiceHTTPAdapter.prototype._buildURI = function (path, data) {
return url.format(uri);
};

ServiceHTTPAdapter.prototype._request = function (method, path, data, body) {
ServiceHTTPAdapter.prototype._request = function (method, path, data, body, headers) {
// add promise wrapper
return when.promise(function (resolve, reject) {
// ------------------------------------------------
request({
method: method,
uri: this._buildURI(path, data),
body: body,
json: _.isObject(body)
method: method,
uri: this._buildURI(path, data),
body: body,
json: _.isObject(body),
headers: headers || {}
},
function (error, response, body) {
if (error) {
Expand Down Expand Up @@ -90,15 +91,15 @@ ServiceHTTPAdapter.prototype._request = function (method, path, data, body) {
/* ---------------------------------------------------
* Public Functions
* --------------------------------------------------- */
ServiceHTTPAdapter.prototype.get = function (path, data) {
return this._request('GET', path, data);
ServiceHTTPAdapter.prototype.get = function (path, data, headers) {
return this._request('GET', path, data, null, headers);
};
ServiceHTTPAdapter.prototype.post = function (path, body) {
return this._request('POST', path, null, body);
ServiceHTTPAdapter.prototype.post = function (path, body, headers) {
return this._request('POST', path, null, body, headers);
};
ServiceHTTPAdapter.prototype.put = function (path, body) {
return this._request('PUT', path, null, body);
ServiceHTTPAdapter.prototype.put = function (path, body, headers) {
return this._request('PUT', path, null, body, headers);
};
ServiceHTTPAdapter.prototype.delete = function (path, data) {
return this._request('DELETE', path, data);
ServiceHTTPAdapter.prototype.delete = function (path, data, headers) {
return this._request('DELETE', path, data, null, headers);
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hyper.io",
"version": "0.6.6",
"version": "0.7.0",
"description": "MicroServices so fast they've gone plaid!",
"homepage": "https://github.com/jstty/hyper.io#readme",
"keywords": [
Expand Down

0 comments on commit 6bb904c

Please sign in to comment.