Skip to content

Commit

Permalink
add support for @angular/common/http (HttpClient) (#2)
Browse files Browse the repository at this point in the history
* add .idea/ to .gitignore

* add support for @angular/common/http (HttpClient)
  • Loading branch information
j2L4e authored and daffl committed Aug 23, 2018
1 parent f8467c5 commit 0f425d7
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 26 deletions.
1 change: 1 addition & 0 deletions packages/rest-client/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ node_modules
.lock-wscript

dist/
.idea/
96 changes: 72 additions & 24 deletions packages/rest-client/dist/feathers-rest-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,53 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"

var Base = require('./base');

var AngularHttpService = function (_Base) {
_inherits(AngularHttpService, _Base);

function AngularHttpService() {
_classCallCheck(this, AngularHttpService);

return _possibleConstructorReturn(this, _Base.apply(this, arguments));
}

AngularHttpService.prototype.request = function request(options) {
var httpClient = this.connection;
var HttpHeaders = this.options.HttpHeaders;

if (!httpClient || !HttpHeaders) {
throw new Error('Please pass angular\'s \'httpClient\' (instance) and and object with \'HttpHeaders\' (class) to feathers-rest');
}

var url = options.url;
var requestOptions = {
// method: options.method,
body: options.body,
headers: new HttpHeaders(Object.assign({ Accept: 'application/json' }, this.options.headers, options.headers))
};

return new Promise(function (resolve, reject) {
httpClient.request(options.method, url, requestOptions).subscribe(resolve, reject);
}).catch(function (error) {
throw error.error || error;
});
};

return AngularHttpService;
}(Base);

module.exports = AngularHttpService;

},{"./base":4}],2:[function(require,module,exports){
'use strict';

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var Base = require('./base');

var AngularService = function (_Base) {
_inherits(AngularService, _Base);

Expand Down Expand Up @@ -49,7 +96,7 @@ var AngularService = function (_Base) {

module.exports = AngularService;

},{"./base":3}],2:[function(require,module,exports){
},{"./base":4}],3:[function(require,module,exports){
'use strict';

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Expand Down Expand Up @@ -93,7 +140,7 @@ var AxiosService = function (_Base) {

module.exports = AxiosService;

},{"./base":3}],3:[function(require,module,exports){
},{"./base":4}],4:[function(require,module,exports){
'use strict';

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Expand Down Expand Up @@ -221,7 +268,7 @@ var Base = function () {

module.exports = Base;

},{"feathers-commons":12,"feathers-errors":15,"qs":19}],4:[function(require,module,exports){
},{"feathers-commons":13,"feathers-errors":16,"qs":20}],5:[function(require,module,exports){
'use strict';

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Expand Down Expand Up @@ -279,7 +326,7 @@ var FetchService = function (_Base) {

module.exports = FetchService;

},{"./base":3}],5:[function(require,module,exports){
},{"./base":4}],6:[function(require,module,exports){
'use strict';

var jQuery = require('./jquery');
Expand All @@ -288,14 +335,16 @@ var Request = require('./request');
var Fetch = require('./fetch');
var Axios = require('./axios');
var Angular = require('./angular');
var AngularHttpClient = require('./angular-http-client');

var transports = {
jquery: jQuery,
superagent: Superagent,
request: Request,
fetch: Fetch,
axios: Axios,
angular: Angular
angular: Angular,
angularHttpClient: AngularHttpClient
};

module.exports = function () {
Expand Down Expand Up @@ -336,7 +385,7 @@ module.exports = function () {
return result;
};

},{"./angular":1,"./axios":2,"./fetch":4,"./jquery":6,"./request":7,"./superagent":8}],6:[function(require,module,exports){
},{"./angular":2,"./angular-http-client":1,"./axios":3,"./fetch":5,"./jquery":7,"./request":8,"./superagent":9}],7:[function(require,module,exports){
'use strict';

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Expand Down Expand Up @@ -395,7 +444,7 @@ var jQueryService = function (_Base) {

module.exports = jQueryService;

},{"./base":3}],7:[function(require,module,exports){
},{"./base":4}],8:[function(require,module,exports){
'use strict';

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Expand Down Expand Up @@ -446,7 +495,7 @@ var RequestService = function (_Base) {

module.exports = RequestService;

},{"./base":3}],8:[function(require,module,exports){
},{"./base":4}],9:[function(require,module,exports){
'use strict';

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Expand Down Expand Up @@ -497,7 +546,7 @@ var SuperagentService = function (_Base) {

module.exports = SuperagentService;

},{"./base":3}],9:[function(require,module,exports){
},{"./base":4}],10:[function(require,module,exports){
(function (process){
/**
* This is the web browser implementation of `debug()`.
Expand Down Expand Up @@ -686,7 +735,7 @@ function localstorage() {
}

}).call(this,require('_process'))
},{"./debug":10,"_process":17}],10:[function(require,module,exports){
},{"./debug":11,"_process":18}],11:[function(require,module,exports){

/**
* This is the common logic for both the Node.js and web browser
Expand Down Expand Up @@ -890,7 +939,7 @@ function coerce(val) {
return val;
}

},{"ms":16}],11:[function(require,module,exports){
},{"ms":17}],12:[function(require,module,exports){
'use strict';

Object.defineProperty(exports, "__esModule", {
Expand Down Expand Up @@ -989,7 +1038,7 @@ var converters = exports.converters = {
function getArguments(method, args) {
return converters[method](args);
}
},{}],12:[function(require,module,exports){
},{}],13:[function(require,module,exports){
'use strict';

Object.defineProperty(exports, "__esModule", {
Expand Down Expand Up @@ -1032,7 +1081,7 @@ exports.default = {
merge: _utils.merge
};
module.exports = exports['default'];
},{"./arguments":11,"./hooks":13,"./utils":14}],13:[function(require,module,exports){
},{"./arguments":12,"./hooks":14,"./utils":15}],14:[function(require,module,exports){
'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
Expand Down Expand Up @@ -1160,7 +1209,7 @@ exports.default = {
convertHookData: convertHookData
};
module.exports = exports['default'];
},{"./utils":14}],14:[function(require,module,exports){
},{"./utils":15}],15:[function(require,module,exports){
(function (process){
'use strict';

Expand Down Expand Up @@ -1434,7 +1483,7 @@ function makeUrl(path) {
return protocol + '://' + host + port + '/' + stripSlashes(path);
}
}).call(this,require('_process'))
},{"_process":17}],15:[function(require,module,exports){
},{"_process":18}],16:[function(require,module,exports){
'use strict';

Object.defineProperty(exports, "__esModule", {
Expand Down Expand Up @@ -1690,8 +1739,7 @@ exports.default = _extends({
errors: errors
}, errors);
module.exports = exports['default'];

},{"debug":9}],16:[function(require,module,exports){
},{"debug":10}],17:[function(require,module,exports){
/**
* Helpers.
*/
Expand Down Expand Up @@ -1845,7 +1893,7 @@ function plural(ms, n, name) {
return Math.ceil(ms / n) + ' ' + name + 's';
}

},{}],17:[function(require,module,exports){
},{}],18:[function(require,module,exports){
// shim for using process in browser
var process = module.exports = {};

Expand Down Expand Up @@ -2031,7 +2079,7 @@ process.chdir = function (dir) {
};
process.umask = function() { return 0; };

},{}],18:[function(require,module,exports){
},{}],19:[function(require,module,exports){
'use strict';

var replace = String.prototype.replace;
Expand All @@ -2051,7 +2099,7 @@ module.exports = {
RFC3986: 'RFC3986'
};

},{}],19:[function(require,module,exports){
},{}],20:[function(require,module,exports){
'use strict';

var stringify = require('./stringify');
Expand All @@ -2064,7 +2112,7 @@ module.exports = {
stringify: stringify
};

},{"./formats":18,"./parse":20,"./stringify":21}],20:[function(require,module,exports){
},{"./formats":19,"./parse":21,"./stringify":22}],21:[function(require,module,exports){
'use strict';

var utils = require('./utils');
Expand Down Expand Up @@ -2238,7 +2286,7 @@ module.exports = function (str, opts) {
return utils.compact(obj);
};

},{"./utils":22}],21:[function(require,module,exports){
},{"./utils":23}],22:[function(require,module,exports){
'use strict';

var utils = require('./utils');
Expand Down Expand Up @@ -2450,7 +2498,7 @@ module.exports = function (object, opts) {
return joined.length > 0 ? prefix + joined : '';
};

},{"./formats":18,"./utils":22}],22:[function(require,module,exports){
},{"./formats":19,"./utils":23}],23:[function(require,module,exports){
'use strict';

var has = Object.prototype.hasOwnProperty;
Expand Down Expand Up @@ -2644,5 +2692,5 @@ exports.isBuffer = function (obj) {
return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
};

},{}]},{},[5])(5)
},{}]},{},[6])(6)
});
2 changes: 1 addition & 1 deletion packages/rest-client/dist/feathers-rest-client.min.js

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions packages/rest-client/lib/angular-http-client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const Base = require('./base');

class AngularHttpService extends Base {
request (options) {
const httpClient = this.connection;
const HttpHeaders = this.options.HttpHeaders;

if (!httpClient || !HttpHeaders) {
throw new Error(`Please pass angular's 'httpClient' (instance) and and object with 'HttpHeaders' (class) to feathers-rest`);
}

const url = options.url;
const requestOptions = {
// method: options.method,
body: options.body,
headers: new HttpHeaders(
Object.assign(
{Accept: 'application/json'},
this.options.headers,
options.headers
)
)
};

return new Promise((resolve, reject) => {
httpClient.request(options.method, url, requestOptions)
.subscribe(resolve, reject);
})
.catch(error => {
throw error.error || error;
});
}
}

module.exports = AngularHttpService;
4 changes: 3 additions & 1 deletion packages/rest-client/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ const Request = require('./request');
const Fetch = require('./fetch');
const Axios = require('./axios');
const Angular = require('./angular');
const AngularHttpClient = require('./angular-http-client');

const transports = {
jquery: jQuery,
superagent: Superagent,
request: Request,
fetch: Fetch,
axios: Axios,
angular: Angular
angular: Angular,
angularHttpClient: AngularHttpClient
};

module.exports = function (base = '') {
Expand Down
Loading

0 comments on commit 0f425d7

Please sign in to comment.