[KC-108] ai api 실행
This commit is contained in:
@@ -14,17 +14,18 @@ public class ExternalHttpClient {
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
public ResponseEntity<String> exchange(
|
||||
String url, HttpMethod method, Object body, HttpHeaders headers) {
|
||||
public <T> ResponseEntity<T> exchange(
|
||||
String url, HttpMethod method, Object body, HttpHeaders headers, Class<T> responseType) {
|
||||
HttpEntity<Object> entity = new HttpEntity<>(body, headers);
|
||||
return restTemplate.exchange(url, method, entity, String.class);
|
||||
return restTemplate.exchange(url, method, entity, responseType);
|
||||
}
|
||||
|
||||
public ExternalCallResult call(String url, HttpMethod method, Object body, HttpHeaders headers) {
|
||||
ResponseEntity<String> res = exchange(url, method, body, headers);
|
||||
public <T> ExternalCallResult<T> call(
|
||||
String url, HttpMethod method, Object body, HttpHeaders headers, Class<T> responseType) {
|
||||
ResponseEntity<T> res = exchange(url, method, body, headers, responseType);
|
||||
int code = res.getStatusCodeValue();
|
||||
return new ExternalCallResult(code, code >= 200 && code < 300, res.getBody());
|
||||
return new ExternalCallResult<>(code, code >= 200 && code < 300, res.getBody());
|
||||
}
|
||||
|
||||
public record ExternalCallResult(int statusCode, boolean success, String body) {}
|
||||
public record ExternalCallResult<T>(int statusCode, boolean success, T body) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user