@@ -24,6 +24,14 @@ const output: OutputDescriptor = {
24
24
} ;
25
25
26
26
export class RestClient {
27
+ /**
28
+ * Perform request
29
+ * Mocks the request call without calling the real backend.
30
+ * @param verb RestAPI verb
31
+ * @param url URL to query
32
+ * @param body Query object as defined by the Query interface
33
+ * @return A TspClientResponse object
34
+ */
27
35
private static async performRequest < T > ( verb : string , url : string , body ?: any ) : Promise < TspClientResponse < T > > {
28
36
return new Promise ( ( resolve , reject ) => {
29
37
let client : TspClientResponse < T > = new TspClientResponse ( response . text , response . status , response . statusText ) ;
@@ -62,6 +70,13 @@ export class RestClient {
62
70
} ) ;
63
71
}
64
72
73
+ /**
74
+ * Perform GET
75
+ * T is the expected type of the json object returned by this request
76
+ * @param url URL to query without query parameters
77
+ * @param parameters Query parameters. Mapped keys and values are used to build the final URL
78
+ * @return A TspClientResponse object
79
+ */
65
80
public static async get < T > ( url : string , parameters ?: Map < string , string > ) : Promise < TspClientResponse < T > > {
66
81
let getUrl = url ;
67
82
if ( parameters ) {
@@ -71,14 +86,35 @@ export class RestClient {
71
86
return this . performRequest < T > ( 'get' , getUrl ) ;
72
87
}
73
88
89
+ /**
90
+ * Perform POST
91
+ * T is the expected type of the json object returned by this request
92
+ * @param url URL to query
93
+ * @param body Query object as defined by the Query interface
94
+ * @return A TspClientResponse object
95
+ */
74
96
public static async post < T > ( url : string , body ?: any ) : Promise < TspClientResponse < T > > {
75
97
return this . performRequest < T > ( 'post' , url , body ) ;
76
98
}
77
99
100
+ /**
101
+ * Perform PUT
102
+ * T is the expected type of the json object returned by this request
103
+ * @param url URL to query
104
+ * @param body Query object as defined by the Query interface
105
+ * @return A TspClientResponse object
106
+ */
78
107
public static async put < T > ( url : string , body ?: any ) : Promise < TspClientResponse < T > > {
79
108
return this . performRequest < T > ( 'put' , url , body ) ;
80
109
}
81
110
111
+ /**
112
+ * Perform DELETE
113
+ * T is the expected type of the json object returned by this request
114
+ * @param url URL to query without query parameters
115
+ * @param parameters Query parameters. Mapped keys and values are use to build the final URL
116
+ * @return A TspClientResponse object
117
+ */
82
118
public static async delete < T > ( url : string , parameters ?: Map < string , string > ) : Promise < TspClientResponse < T > > {
83
119
let deleteUrl = url ;
84
120
if ( parameters ) {
@@ -88,6 +124,11 @@ export class RestClient {
88
124
return this . performRequest < T > ( 'delete' , deleteUrl ) ;
89
125
}
90
126
127
+ /**
128
+ * Encode URL parameters
129
+ * @param parameters Query parameters. Mapped keys and values are used to build the final URL
130
+ * @return Encoded string
131
+ */
91
132
private static encodeURLParameters ( parameters : Map < string , string > ) : string {
92
133
if ( parameters . size ) {
93
134
const urlParameters : string = '?' ;
@@ -100,6 +141,11 @@ export class RestClient {
100
141
return '' ;
101
142
}
102
143
144
+ /**
145
+ * Extract parameters
146
+ * @param url URL string
147
+ * @return String containing the parameters extracted from the url
148
+ */
103
149
public static extractParameters ( url : string ) : string {
104
150
const topic = url . includes ( 'traces' ) ? 'traces' : 'experiments' ;
105
151
const ar = url . split ( topic + '/' ) ;
0 commit comments