UNPKG

@platform/cell.client

Version:

A strongly typed HTTP client for operating with a CellOS service end-point.

68 lines (67 loc) 2.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var common_1 = require("../common"); var HttpClientNs = (function () { function HttpClientNs(args) { var urls = args.urls; this.args = args; this.uri = common_1.Uri.parse(args.uri); this.url = urls.ns(args.uri); } HttpClientNs.create = function (args) { return new HttpClientNs(args); }; HttpClientNs.prototype.toString = function () { return this.uri.toString(); }; HttpClientNs.prototype.exists = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { var res; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, this.args.http.get(this.url.info.toString())]; case 1: res = _a.sent(); return [2, res.status.toString().startsWith('2')]; } }); }); }; HttpClientNs.prototype.read = function (options) { if (options === void 0) { options = {}; } return tslib_1.__awaiter(this, void 0, void 0, function () { var http, url, res; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: http = this.args.http; url = this.url.info.query(options).toString(); return [4, http.get(url)]; case 1: res = _a.sent(); return [2, common_1.util.fromHttpResponse(res).toClientResponse()]; } }); }); }; HttpClientNs.prototype.write = function (data, options) { if (options === void 0) { options = {}; } return tslib_1.__awaiter(this, void 0, void 0, function () { var http, url, res; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: http = this.args.http; url = this.url.info.query(options).toString(); return [4, http.post(url, data)]; case 1: res = _a.sent(); return [2, common_1.util.fromHttpResponse(res).toClientResponse()]; } }); }); }; return HttpClientNs; }()); exports.HttpClientNs = HttpClientNs;