diff options
Diffstat (limited to 'packages/taler-wallet-core/src/util/http.ts')
-rw-r--r-- | packages/taler-wallet-core/src/util/http.ts | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/util/http.ts b/packages/taler-wallet-core/src/util/http.ts index 1a2459f7e..1ec9c2f50 100644 --- a/packages/taler-wallet-core/src/util/http.ts +++ b/packages/taler-wallet-core/src/util/http.ts @@ -17,6 +17,8 @@ /** * Helpers for doing XMLHttpRequest-s that are based on ES6 promises. * Allows for easy mocking for test cases. + * + * The API is inspired by the HTML5 fetch API. */ /** @@ -47,16 +49,20 @@ export interface HttpResponse { headers: Headers; json(): Promise<any>; text(): Promise<string>; + bytes(): Promise<ArrayBuffer>; } export interface HttpRequestOptions { + method?: "POST" | "PUT" | "GET"; headers?: { [name: string]: string }; timeout?: Duration; + body?: string | ArrayBuffer | ArrayBufferView; } export enum HttpResponseStatus { Ok = 200, Gone = 210, + PaymentRequired = 402, } /** @@ -82,6 +88,12 @@ export class Headers { this.headerMap.set(normalizedName, value); } } + + toJSON(): any { + const m: Record<string, string> = {}; + this.headerMap.forEach((v, k) => m[k] = v); + return m; + } } /** @@ -104,6 +116,14 @@ export interface HttpRequestLibrary { body: any, opt?: HttpRequestOptions, ): Promise<HttpResponse>; + + /** + * Make an HTTP POST request with a JSON body. + */ + fetch( + url: string, + opt?: HttpRequestOptions, + ): Promise<HttpResponse>; } type TalerErrorResponse = { |