정부혜택 정보 (API 구현)
2025 영구 불임예상 난자·정자 냉동 지원보건복지부
서비스분야보건·의료
신청방법기타 온라인신청||방문신청
신청기한생식세포 채취일로부터 6개월 (2025.1.1. 을 포함하여 그 이후에 생식세포를 채취한 자일 것)
자세히 보기로직 설명
- API URL - https://api.odcloud.kr/api/gov24/v3/serviceList
- serviceKey - authkey ( 참고 : https://www.data.go.kr/data/15113968/openapi.do )
- 파라미터
- 등록일시(이상) : cond[등록일시::GTE]
- 등록일시(이하) : cond[등록일시::LTE]
- 소관기관유형 : cond[소관기관유형::LIKE]
- 기타 파라미터 : https://www.data.go.kr/data/15113968/openapi.do 참고
- 사용한 로직
/** * 정부혜택 서비스 관련 API */ export class PublicService { /** * @param {string} authkey - data.go.kr 인증 키 */ constructor(authkey) { this.authkey = authkey; } async getList(opts) { const { startDate, endDate, page=1, perPage=9, organ } = opts; let conds = []; if(startDate) { const strDate = DateUtil.format('yyyyMMdd', startDate); conds.push(encodeURIComponent('cond[등록일시::GTE]')+`=${strDate}`); } else { const date = new Date(); date.setFullYear(date.getFullYear() - 1); date.setMonth(0); date.setDate(1); const strDate = DateUtil.format('yyyyMMdd', date); conds.push(encodeURIComponent('cond[등록일시::GTE]')+`=${strDate}`); } if(endDate) { const strDate = DateUtil.format('yyyyMMdd', endDate); conds.push(encodeURIComponent('cond[등록일시::LTE]')+`=${strDate}`); } if(organ) { conds.push(encodeURIComponent('cond[소관기관유형::LIKE]')+`=${organ}`); } const cond = conds.join('&'); const fetchUrl = 'https://api.odcloud.kr/api/gov24/v3/serviceList'; const url = `${fetchUrl}?serviceKey=${this.authkey}&page=${page}&perPage=${perPage}&${cond}`; const res = await fetch(url, { headers: { 'accept': 'application/json' } }); if (!res.ok) { throw new Error('API 응답 실패'); } return await res.json(); } }