forked from jasonfill/ColdFusion-ElasticSearch-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Base.cfc
35 lines (23 loc) · 823 Bytes
/
Base.cfc
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
component output="false" {
public function init(){
return this;
}
package struct function doRequest(required string Endpoint, required string Resource, string Method="GET", string Body=""){
var httpSvc = new http();
var response = new SearchResponse();
httpSvc.setUrl(arguments.endpoint & Arguments.Resource);
httpSvc.setMethod(Arguments.Method);
if(len(trim(Arguments.Body))){
httpSvc.addParam(type="body",value=Arguments.Body);
}
var sendResult = httpSvc.send().getPrefix();
response.setStatusCode(sendResult.status_code);
response.setStatus(sendResult.StatusCode);
response.setBody(deserializeJSON(sendResult.FileContent));
response.setHeader(sendResult.responseHeader);
if(response.getStatusCode() == "200"){
response.setSuccess(true);
}
return response;
}
}