-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
RestClient.ts
61 lines (55 loc) · 2.21 KB
/
RestClient.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import type { HttpClientRequestOptions } from './HttpClientRequestOptions.js'
/**
* A REST API client which will provide GET, POST, PUT, PATCH, DELETE methods
* The client provides error and timeout handling and tries to decode the responses
*/
export interface RestClient {
/**
* Set the Auth-Bearer-Token for all following requests
* @param token the bearer token
*/
setBearerToken(token: string | undefined): void
/**
* Make a GET request against baseUrl+path
* Returns body text if response content type is not set to `application/json`.
* If response content type is `application/json`, the JSON parsed result will be returned
* @param path
* @param options
*/
get<T>(path: string, options: HttpClientRequestOptions): Promise<T>
/**
* Make a POST request against baseUrl+path
* Returns body text if response content type is not set to `application/json`.
* If response content type is `application/json`, the JSON parsed result will be returned
* @param path
* @param payload
* @param options
*/
post<T>(path: string, payload: unknown, options: HttpClientRequestOptions): Promise<T>
/**
* Make a PUT request against baseUrl+path
* Returns body text if response content type is not set to `application/json`.
* If response content type is `application/json`, the JSON parsed result will be returned
* @param path
* @param payload
* @param options
*/
put<T>(path: string, payload: unknown, options: HttpClientRequestOptions): Promise<T>
/**
* Make a PATCH request against baseUrl+path
* Returns body text if response content type is not set to `application/json`.
* If response content type is `application/json`, the JSON parsed result will be returned
* @param path
* @param payload
* @param options
*/
patch<T>(path: string, payload: unknown, options: HttpClientRequestOptions): Promise<T>
/**
* Make a DELETE request against baseUrl+path
* Returns body text if response content type is not set to `application/json`.
* If response content type is `application/json`, the JSON parsed result will be returned
* @param path
* @param options
*/
delete<T>(path: string, options: HttpClientRequestOptions): Promise<T>
}