typed-rest-client
Advanced tools
Comparing version 0.15.1 to 1.0.0
{ | ||
"name": "typed-rest-client", | ||
"version": "0.15.1", | ||
"version": "1.0.0", | ||
"description": "Node Rest and Http Clients for use with TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "./RestClient.js", |
@@ -36,13 +36,13 @@ /// <reference types="node" /> | ||
* Be aware that not found returns a null. Other error conditions reject the promise | ||
* @param {string} requestUrl - fully qualified or relative url | ||
* @param {string} resource - fully qualified url or relative path | ||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object | ||
*/ | ||
get<T>(requestUrl: string, options?: IRequestOptions): Promise<IRestResponse<T>>; | ||
get<T>(resource: string, options?: IRequestOptions): Promise<IRestResponse<T>>; | ||
/** | ||
* Deletes a resource from an endpoint | ||
* Be aware that not found returns a null. Other error conditions reject the promise | ||
* @param {string} requestUrl - fully qualified or relative url | ||
* @param {string} resource - fully qualified or relative url | ||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object | ||
*/ | ||
del<T>(requestUrl: string, options?: IRequestOptions): Promise<IRestResponse<T>>; | ||
del<T>(resource: string, options?: IRequestOptions): Promise<IRestResponse<T>>; | ||
/** | ||
@@ -52,6 +52,6 @@ * Creates resource(s) from an endpoint | ||
* Be aware that not found returns a null. Other error conditions reject the promise | ||
* @param {string} requestUrl - fully qualified or relative url | ||
* @param {string} resource - fully qualified or relative url | ||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object | ||
*/ | ||
create<T>(requestUrl: string, resources: any, options?: IRequestOptions): Promise<IRestResponse<T>>; | ||
create<T>(resource: string, resources: any, options?: IRequestOptions): Promise<IRestResponse<T>>; | ||
/** | ||
@@ -61,6 +61,6 @@ * Updates resource(s) from an endpoint | ||
* Be aware that not found returns a null. Other error conditions reject the promise | ||
* @param {string} requestUrl - fully qualified or relative url | ||
* @param {string} resource - fully qualified or relative url | ||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object | ||
*/ | ||
update<T>(requestUrl: string, resources: any, options?: IRequestOptions): Promise<IRestResponse<T>>; | ||
update<T>(resource: string, resources: any, options?: IRequestOptions): Promise<IRestResponse<T>>; | ||
/** | ||
@@ -70,6 +70,6 @@ * Replaces resource(s) from an endpoint | ||
* Be aware that not found returns a null. Other error conditions reject the promise | ||
* @param {string} requestUrl - fully qualified or relative url | ||
* @param {string} resource - fully qualified or relative url | ||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object | ||
*/ | ||
replace<T>(requestUrl: string, resources: any, options?: IRequestOptions): Promise<IRestResponse<T>>; | ||
replace<T>(resource: string, resources: any, options?: IRequestOptions): Promise<IRestResponse<T>>; | ||
uploadStream<T>(verb: string, requestUrl: string, stream: NodeJS.ReadableStream, options?: IRequestOptions): Promise<IRestResponse<T>>; | ||
@@ -76,0 +76,0 @@ private _headersFromOptions(options, contentType?); |
@@ -46,8 +46,8 @@ "use strict"; | ||
* Be aware that not found returns a null. Other error conditions reject the promise | ||
* @param {string} requestUrl - fully qualified or relative url | ||
* @param {string} resource - fully qualified url or relative path | ||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object | ||
*/ | ||
get(requestUrl, options) { | ||
get(resource, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let url = util.getUrl(requestUrl, this._baseUrl); | ||
let url = util.getUrl(resource, this._baseUrl); | ||
let res = yield this.client.get(url, this._headersFromOptions(options)); | ||
@@ -60,8 +60,8 @@ return this._processResponse(res, options); | ||
* Be aware that not found returns a null. Other error conditions reject the promise | ||
* @param {string} requestUrl - fully qualified or relative url | ||
* @param {string} resource - fully qualified or relative url | ||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object | ||
*/ | ||
del(requestUrl, options) { | ||
del(resource, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let url = util.getUrl(requestUrl, this._baseUrl); | ||
let url = util.getUrl(resource, this._baseUrl); | ||
let res = yield this.client.del(url, this._headersFromOptions(options)); | ||
@@ -75,8 +75,8 @@ return this._processResponse(res, options); | ||
* Be aware that not found returns a null. Other error conditions reject the promise | ||
* @param {string} requestUrl - fully qualified or relative url | ||
* @param {string} resource - fully qualified or relative url | ||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object | ||
*/ | ||
create(requestUrl, resources, options) { | ||
create(resource, resources, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let url = util.getUrl(requestUrl, this._baseUrl); | ||
let url = util.getUrl(resource, this._baseUrl); | ||
let headers = this._headersFromOptions(options, true); | ||
@@ -92,8 +92,8 @@ let data = JSON.stringify(resources, null, 2); | ||
* Be aware that not found returns a null. Other error conditions reject the promise | ||
* @param {string} requestUrl - fully qualified or relative url | ||
* @param {string} resource - fully qualified or relative url | ||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object | ||
*/ | ||
update(requestUrl, resources, options) { | ||
update(resource, resources, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let url = util.getUrl(requestUrl, this._baseUrl); | ||
let url = util.getUrl(resource, this._baseUrl); | ||
let headers = this._headersFromOptions(options, true); | ||
@@ -109,8 +109,8 @@ let data = JSON.stringify(resources, null, 2); | ||
* Be aware that not found returns a null. Other error conditions reject the promise | ||
* @param {string} requestUrl - fully qualified or relative url | ||
* @param {string} resource - fully qualified or relative url | ||
* @param {IRequestOptions} requestOptions - (optional) requestOptions object | ||
*/ | ||
replace(requestUrl, resources, options) { | ||
replace(resource, resources, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let url = util.getUrl(requestUrl, this._baseUrl); | ||
let url = util.getUrl(resource, this._baseUrl); | ||
let headers = this._headersFromOptions(options, true); | ||
@@ -117,0 +117,0 @@ let data = JSON.stringify(resources, null, 2); |
/** | ||
* creates an url from a request url and optional base url (http://server:8080) | ||
* @param {string} requestUrl - a fully qualified url or relative url | ||
* @param {string} resource - a fully qualified url or relative path | ||
* @param {string} baseUrl - an optional baseUrl (http://server:8080) | ||
* @return {string} - resultant url | ||
*/ | ||
export declare function getUrl(requestUrl: string, baseUrl?: string): string; | ||
export declare function getUrl(resource: string, baseUrl?: string): string; |
22
Util.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const url = require("url"); | ||
const path = require("path"); | ||
/** | ||
* creates an url from a request url and optional base url (http://server:8080) | ||
* @param {string} requestUrl - a fully qualified url or relative url | ||
* @param {string} resource - a fully qualified url or relative path | ||
* @param {string} baseUrl - an optional baseUrl (http://server:8080) | ||
* @return {string} - resultant url | ||
*/ | ||
function getUrl(requestUrl, baseUrl) { | ||
function getUrl(resource, baseUrl) { | ||
if (!baseUrl) { | ||
return requestUrl; | ||
return resource; | ||
} | ||
let base = url.parse(baseUrl); | ||
// requestUrl (specific per request) always wins | ||
let combined = url.parse(requestUrl); | ||
combined.protocol = combined.protocol || base.protocol; | ||
combined.auth = combined.auth || base.auth; | ||
combined.host = combined.host || base.host; | ||
// path from requestUrl always wins | ||
let res = url.format(combined); | ||
// resource (specific per request) eliments take priority | ||
let resultantUrl = url.parse(resource); | ||
resultantUrl.protocol = resultantUrl.protocol || base.protocol; | ||
resultantUrl.auth = resultantUrl.auth || base.auth; | ||
resultantUrl.host = resultantUrl.host || base.host; | ||
let basePathComponent = base.pathname === '/' ? '' : base.pathname; | ||
resultantUrl.pathname = path.posix.resolve(basePathComponent, resultantUrl.pathname); | ||
let res = url.format(resultantUrl); | ||
return res; | ||
} | ||
exports.getUrl = getUrl; |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
61814
1263
0