-
Notifications
You must be signed in to change notification settings - Fork 0
004. Codef API 호출
Haebin edited this page Nov 13, 2024
·
1 revision
Note
아래 예제는 모두 건강보험공단 > 건강검진결과 API 개발가이드를 기반으로 작성됐어요.
- path: 실제 Codef API에 요청할 경로.
/v1/kr/***/
형태의 String 값
- organization : 모든 Codef API의 필수 값. 각 상품 개발가이드에 적힌 고정 값 입력
- 이 외 요청부를 개발가이드
입력부(Input)
에 맞게 입력해주세요.
Important
Codef API 상품 호출 메소드
EasyCodef easyCodef; // 002. 시크릿 키 기반 EasyCodef 객체 생성 Page 참고
EasyCodefRequest request; // 003. 상품 요청 객체 생성 Page 참고
EasyCodefResponse response = easyCodef.requestProduct(request);
Warning
requestProduct 메소드는 아래의 예외 사항들을 같이 검증하고, 검증에 실패하면 예외를 반환해요.
- codef OAuth API와 통신에 실패하는 경우 (https://oauth.codef.io)
- codef API와 통신에 실패하는 경우 (https://api.codef.io | https://development.codef.io)
- codef API가 200 이외의 응답 코드를 반환하는 경우
Note
- 아래 객체는 실제 Codef API의 응답부를 객체 형식으로 구현한 레코드예요.
public record EasyCodefResponse(
Result result,
Object data
) {
public static final String RESULT = "result";
public static final String DATA = "data";
public String code() {
return this.result().code();
}
public String transactionId() {
return this.result().transactionId();
}
public record Result(
String code,
String extraMessage,
String message,
String transactionId
) {
}
}
Tip
Codef API는 아래 응답처럼 일정한 형식으로 반환되는 형태를 가져요.
EasyCodef는 이러한 http 응답부를 EasyCodefResponse
객체에 자동으로 바인딩해서 제공해요.
Important
편의 메소드
- response.code()
→ Codef API의 응답 코드를 반환합니다.
→ 응답코드와 관련된 정보는 개발가이드 > 공통가이드 > 오류코드에서 자세히 확인 가능해요.
- response.transactionId()
→ Codef API의 트랜잭션 Id를 반환해요.
→ 간편인증 및 고객 문의를 위해 활용되는 모든 요청의 고유 Key 값이에요.
{ "result": { "code": "CF-00000", "extraMessage": "", "message": "성공", "transactionId": "673c243fec82470d0003129f" }, "data": { "resPreviewList": [ { "resCheckupYear": "2023", "resCheckupDate": "0221", "resCheckupPlace": "", "resHeight": "176.0", "resWeight": "76.0", "resWaist": "75.0", "resBMI": "24.5", "resSight": "1.2/1.2", "resHearing": "정상/정상", "resBloodPressure": "127/80", "resUrinaryProtein": "음성", "resHemoglobin": "16.4", "resFastingBloodSuger": "74", "resTotalCholesterol": "225", "resHDLCholesterol": "58", "resTriglyceride": "103", "resLDLCholesterol": "146", "resSerumCreatinine": "0.9", "resGFR": "110", "resAST": "35", "resALT": "50", "resyGPT": "26", "resTBChestDisease": "정상", "resOsteoporosis": "", "resJudgement": "의심" } ] } }
Note
- 아래 객체는 실제 Codef API의 응답부의 Result 응답을 객체 형식으로 구현한 레코드예요.
public record Result(
String code,
String extraMessage,
String message,
String transactionId
) {
}
Tip
- Codef API는 아래 응답처럼 일정한 형식으로 반환되는 형태를 가져요.
- EasyCodef는 이러한 http 응답부를
EasyCodefResponse
객체에 자동으로 바인딩해서 제공해요.
{
"result": {
"code": "CF-00000",
"extraMessage": "",
"message": "성공",
"transactionId": "673c243fec82470d0003129f"
}
}
Important
응답 코드가 CF-03002
라면, 추가인증이 필요한 상품이에요.
005. 간편인증 요청 (CF‐03002) 를 참고하세요.
Note
- 아래 객체는 실제 Codef API의 응답부의 Data를 Object 객체에 바인딩 한 객체에요.
public Object data;
Tip
- EasyCodef Java V2는
fastjson2
오픈소스 라이브러리를 의존해 간단하게 파싱이 가능해요.
- Object 객체 파싱에 대한 자세한 내용은 fastjson2 라이브러리를 확인할 수 있어요.
// JSON 문자열을 JSONObject로 변환
public Object data; // Codef API Output
JSONObject jsonObject = JSON.parseObject(data);
// resLDLCholesterol 값을 가져오기
String resLDLCholesterol = jsonObject
.getJSONObject("data")
.getJSONArray("resPreviewList")
.getJSONObject(0)
.getString("resLDLCholesterol");
{
"data": {
"resPreviewList": [
{
"resCheckupYear": "2023",
"resCheckupDate": "0221",
"resCheckupPlace": "",
"resHeight": "176.0",
"resWeight": "76.0",
"resWaist": "75.0",
"resBMI": "24.5",
"resSight": "1.2/1.2",
"resHearing": "정상/정상",
"resBloodPressure": "127/80",
"resUrinaryProtein": "음성",
"resHemoglobin": "16.4",
"resFastingBloodSuger": "74",
"resTotalCholesterol": "225",
"resHDLCholesterol": "58",
"resTriglyceride": "103",
"resLDLCholesterol": "146",
"resSerumCreatinine": "0.9",
"resGFR": "110",
"resAST": "35",
"resALT": "50",
"resyGPT": "26",
"resTBChestDisease": "정상",
"resOsteoporosis": "",
"resJudgement": "의심"
}
]
}
}
MIT © Hectodata Co., Ltd | LICENSE