@@ -49,6 +49,16 @@ const NO_DELAY = 0;
49
49
50
50
const MOCK_DEFAULT_DELAY = 500 ;
51
51
52
+ export enum RequestMethodParams {
53
+ get = 'Get' ,
54
+ post = 'Post' ,
55
+ put = 'Put' ,
56
+ delete = 'Delete' ,
57
+ options = 'Options' ,
58
+ head = 'Head' ,
59
+ patch = 'Patch'
60
+ }
61
+
52
62
export class HttpRestUtils {
53
63
54
64
public static http : HttpClient = null ;
@@ -116,7 +126,7 @@ export class HttpRestUtils {
116
126
target [ RESOURCE_METADATA_ROOT ] [ entityType ] = metadataObj ;
117
127
}
118
128
119
- public static requestMethod ( requestMethodName : string ) : any {
129
+ public static requestMethod ( requestMethodName : RequestMethodParams ) : any {
120
130
// @dynamic
121
131
return ( target : any , key : string , descriptor : any ) => {
122
132
const originalFunction = descriptor . value ;
@@ -150,7 +160,7 @@ export class HttpRestUtils {
150
160
if ( HttpRestUtils . ifUseMock ( callConfig ) ) { // If "use mock" is true, call original function, to get mock directly from function
151
161
return HttpRestUtils . processIfUseMock ( responseIndex , args , newArgs , originalFunction ) ;
152
162
}
153
- const request = HttpRestUtils . http . request ( requestMethodName , url , params ) ;
163
+ const request = HttpRestUtils . getRequest ( callConfig ) ;
154
164
155
165
156
166
@@ -170,6 +180,27 @@ export class HttpRestUtils {
170
180
} ;
171
181
}
172
182
183
+ private static getRequest ( callConfig : CallConfig ) {
184
+ switch ( callConfig . requestMethodName ) {
185
+ case RequestMethodParams . get :
186
+ return HttpRestUtils . http . get ( callConfig . url , callConfig . params ) ;
187
+ case RequestMethodParams . post :
188
+ return HttpRestUtils . http . post ( callConfig . url , callConfig . params ) ;
189
+ case RequestMethodParams . put :
190
+ return HttpRestUtils . http . put ( callConfig . url , callConfig . params ) ;
191
+ case RequestMethodParams . delete :
192
+ return HttpRestUtils . http . delete ( callConfig . url , callConfig . params ) ;
193
+ case RequestMethodParams . options :
194
+ return HttpRestUtils . http . options ( callConfig . url , callConfig . params ) ;
195
+ case RequestMethodParams . head :
196
+ return HttpRestUtils . http . head ( callConfig . url , callConfig . params ) ;
197
+ case RequestMethodParams . patch :
198
+ return HttpRestUtils . http . patch ( callConfig . url , callConfig . params ) ;
199
+ default :
200
+ return HttpRestUtils . http . request ( callConfig . requestMethodName , callConfig . url , callConfig . params ) ;
201
+ }
202
+ }
203
+
173
204
private static ifUseMock ( callConfig : CallConfig ) : boolean | Function {
174
205
let useMock : boolean | Function = HttpRestUtils . appInjector . get ( HTTP_ANNOTATIONS_USE_MOCKS , false ) ;
175
206
if ( typeof useMock === 'function' ) {
0 commit comments