정부혜택 정보 (API 구현)
난임치료휴가 급여고용노동부
서비스분야임신·출산
신청방법기타 온라인신청||방문신청||직접입력
신청기한휴가를 시작한 날 이후 1개월부터 휴가가 끝난 날 이후 12개월 이내에 신청(분할사용 시 휴가가 끝난 날 이후 일괄하여 신청)
자세히 보기로직 설명
- 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(); } }