diff options
author | Florian Dold <florian@dold.me> | 2020-12-02 14:55:04 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2020-12-02 14:55:04 +0100 |
commit | 89f1a281fea66b986fc0a003dc10446f6ed6e4a2 (patch) | |
tree | 8ffe90d572bc6967ee86bdcffc1eb6dc1240d17c /packages/taler-wallet-core/src/util/http.ts | |
parent | 0828e65f8845dc4b148c0d3b0697fb589b338239 (diff) | |
download | wallet-core-89f1a281fea66b986fc0a003dc10446f6ed6e4a2.tar.gz wallet-core-89f1a281fea66b986fc0a003dc10446f6ed6e4a2.tar.bz2 wallet-core-89f1a281fea66b986fc0a003dc10446f6ed6e4a2.zip |
backup WIP
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 = { |