@frui.ts/apiclient
Advanced tools
Comparing version 0.16.0-beta.2 to 0.16.0-beta.3
import { IApiConnector } from "./types"; | ||
import { StringifyOptions } from "query-string"; | ||
export declare function appendAcceptJsonHeader(params?: RequestInit): RequestInit; | ||
export declare function appendUrl(base: string, ...segments: any[]): string; | ||
export declare class RestRequestBuilder { | ||
@@ -7,3 +9,5 @@ protected apiConnector: IApiConnector; | ||
protected params?: RequestInit | undefined; | ||
static DefaultQueryStringOptions: StringifyOptions; | ||
protected urlValue: string; | ||
queryStringOptions?: StringifyOptions; | ||
get url(): string; | ||
@@ -28,4 +32,4 @@ constructor(apiConnector: IApiConnector, baseUrl: string, params?: RequestInit | undefined); | ||
withBaseUrl(url: string): this; | ||
getQueryString(query: any): string; | ||
protected appendQuery(url: string, query?: any): string; | ||
} | ||
export declare function appendUrl(base: string, ...segments: any[]): string; |
@@ -14,17 +14,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var query_string_1 = require("query-string"); | ||
var cleanupRegex = /\/+$/g; | ||
function getValueForUri(input) { | ||
if (input instanceof Date) { | ||
return input.toISOString(); | ||
} | ||
else { | ||
return input; | ||
} | ||
} | ||
function getQueryString(query) { | ||
return Object.keys(query) | ||
.filter(function (prop) { return query[prop] || query[prop] === 0; }) | ||
.map(function (prop) { return encodeURIComponent(prop) + "=" + encodeURIComponent(getValueForUri(query[prop])); }) | ||
.join("&"); | ||
} | ||
var jsonContentType = "application/json,text/json"; | ||
@@ -35,2 +22,14 @@ function appendAcceptJsonHeader(params) { | ||
exports.appendAcceptJsonHeader = appendAcceptJsonHeader; | ||
function appendUrl(base) { | ||
var segments = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
segments[_i - 1] = arguments[_i]; | ||
} | ||
var result = base.replace(cleanupRegex, ""); | ||
segments.forEach(function (x) { | ||
result += "/" + x; | ||
}); | ||
return result; | ||
} | ||
exports.appendUrl = appendUrl; | ||
var RestRequestBuilder = (function () { | ||
@@ -116,20 +115,13 @@ function RestRequestBuilder(apiConnector, baseUrl, params) { | ||
}; | ||
RestRequestBuilder.prototype.getQueryString = function (query) { | ||
var _a; | ||
return query_string_1.stringify(query, (_a = this.queryStringOptions) !== null && _a !== void 0 ? _a : RestRequestBuilder.DefaultQueryStringOptions); | ||
}; | ||
RestRequestBuilder.prototype.appendQuery = function (url, query) { | ||
return query ? url + "?" + getQueryString(query) : url; | ||
return query ? url + "?" + this.getQueryString(query) : url; | ||
}; | ||
RestRequestBuilder.DefaultQueryStringOptions = { skipNull: true }; | ||
return RestRequestBuilder; | ||
}()); | ||
exports.RestRequestBuilder = RestRequestBuilder; | ||
function appendUrl(base) { | ||
var segments = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
segments[_i - 1] = arguments[_i]; | ||
} | ||
var result = base.replace(cleanupRegex, ""); | ||
segments.forEach(function (x) { | ||
result += "/" + x; | ||
}); | ||
return result; | ||
} | ||
exports.appendUrl = appendUrl; | ||
//# sourceMappingURL=restRequestBuilder.js.map |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "0.16.0-beta.2", | ||
"version": "0.16.0-beta.3", | ||
"description": "Frui.ts helpers for HTTP communication", | ||
@@ -36,5 +36,6 @@ "keywords": [ | ||
"dependencies": { | ||
"@frui.ts/helpers": "^0.16.0-beta.2" | ||
"@frui.ts/helpers": "^0.16.0-beta.3", | ||
"query-string": "^6.9.0" | ||
}, | ||
"gitHead": "769c12e8d1bb8625dc1482fbae7185f6b5e123b1" | ||
"gitHead": "467e9c7dae871601a3451aa26091703433d2d8cb" | ||
} |
Sorry, the diff of this file is not supported yet
37479
2
359
+ Addedquery-string@^6.9.0
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addedfilter-obj@1.1.0(transitive)
+ Addedquery-string@6.14.1(transitive)
+ Addedsplit-on-first@1.1.0(transitive)
+ Addedstrict-uri-encode@2.0.0(transitive)