UNPKG

ngx-restful-client

Version:

The ultimate Angular library to exquisitely declare and implement the REST APIs you'll use in your application.

120 lines (118 loc) 5.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var http_1 = require("@angular/common/http"); var core_1 = require("../core"); var http_options_builder_1 = require("./http-options-builder"); var methods_1 = require("./methods"); /** * Responsável por prover os métodos a serem utilizados nas requisições para uma determinada URI. * Os retornos serão utilizados para recuperar o tipo de resposta e a observação necessária à requisição. * Para que funcione, devem ser providos o HttoClient e a URI desejada. */ var HttpMethodDispatcher = /** @class */ (function () { function HttpMethodDispatcher(http, uri) { this.http = http; this.uri = uri; if (!(http instanceof http_1.HttpClient)) { throw Error('HttpMethodDispatcher only work propertly with an instance of HttpClient. Please provide one.'); } } HttpMethodDispatcher.prototype.get = function (options) { return this.doGet('', options); }; /** * As default, will return an Observable that returns a JSON. If other return type is * needed, check the httpGet and doHttpGet. * * @see HttpMethodDispatcher.httpGet * @see HttpMethodDispatcher.doHttpGet * @param path * @param options */ HttpMethodDispatcher.prototype.doGet = function (path, options) { return this.httpGet(path, options).json().body(); }; HttpMethodDispatcher.prototype.doHttpGet = function (options) { return this.httpGet('', options); }; HttpMethodDispatcher.prototype.httpGet = function (path, options) { var opts = http_options_builder_1.configureOptions(options); var fullPath = "" + this.uri + path; core_1.logger.debug("[GET] " + fullPath, { options: opts }); return new methods_1.HttpGet(fullPath, this.http, opts); }; HttpMethodDispatcher.prototype.put = function (body, options) { if (body === void 0) { body = null; } return this.doPut('', body, options); }; HttpMethodDispatcher.prototype.doPut = function (path, body, options) { if (body === void 0) { body = null; } return this.httpPut(path, body, options).json().body(); }; HttpMethodDispatcher.prototype.doHttpPut = function (body, options) { if (body === void 0) { body = null; } return this.httpPut('', body, options); }; HttpMethodDispatcher.prototype.httpPut = function (path, body, options) { if (body === void 0) { body = null; } var opts = http_options_builder_1.configureOptions(options); var fullPath = "" + this.uri + path; core_1.logger.debug("[PUT] " + fullPath, { body: body, options: opts }); return new methods_1.HttpPut(fullPath, this.http, body, opts); }; HttpMethodDispatcher.prototype.patch = function (body, options) { if (body === void 0) { body = null; } return this.doPatch('', body, options); }; HttpMethodDispatcher.prototype.doPatch = function (path, body, options) { if (body === void 0) { body = null; } return this.httpPatch(path, body, options).json().body(); }; HttpMethodDispatcher.prototype.doHttpPatch = function (body, options) { if (body === void 0) { body = null; } return this.httpPatch('', body, options); }; HttpMethodDispatcher.prototype.httpPatch = function (path, body, options) { if (body === void 0) { body = null; } var opts = http_options_builder_1.configureOptions(options); var fullPath = "" + this.uri + path; core_1.logger.debug("[PATCH] " + fullPath, { body: body, options: opts }); return new methods_1.HttpPatch(fullPath, this.http, body, opts); }; HttpMethodDispatcher.prototype.post = function (body, options) { if (body === void 0) { body = null; } return this.doPost('', body, options); }; HttpMethodDispatcher.prototype.doPost = function (path, body, options) { if (body === void 0) { body = null; } return this.httpPost(path, body, options).json().body(); }; HttpMethodDispatcher.prototype.doHttpPost = function (body, options) { if (body === void 0) { body = null; } return this.httpPost('', body, options); }; HttpMethodDispatcher.prototype.httpPost = function (path, body, options) { if (body === void 0) { body = null; } var opts = http_options_builder_1.configureOptions(options); var fullPath = "" + this.uri + path; core_1.logger.debug("[POST] " + fullPath, { body: body, options: opts }); return new methods_1.HttpPost(fullPath, this.http, body, opts); }; HttpMethodDispatcher.prototype.delete = function (options) { return this.doDelete('', options); }; HttpMethodDispatcher.prototype.doDelete = function (path, options) { return this.httpDelete(path, options).json().body(); }; HttpMethodDispatcher.prototype.doHttoDelete = function (options) { return this.httpDelete('', options); }; HttpMethodDispatcher.prototype.httpDelete = function (path, options) { var opts = http_options_builder_1.configureOptions(options); var fullPath = "" + this.uri + path; core_1.logger.debug("[DELETE] " + fullPath, { options: opts }); return new methods_1.HttpDelete(fullPath, this.http, opts); }; return HttpMethodDispatcher; }()); exports.HttpMethodDispatcher = HttpMethodDispatcher;