[Git]JavaScript, Git Api를 이용해 파일, README 내용 받아오기

ham·2022년 4월 26일
post-thumbnail

파일내용 받아오는 법

fetch("https://api.github.com/repos/{소유자이름}/{레포이름}/contents/{파일이름}")
            .then((response) => response.json())
            .then((data) =>{
                console.log(data) // json 파일
                console.log(data.content) //파일 내용 base64로 받아와진다
                console.log(decodeURIComponent(atob(data.content))); //utf-8로 디코딩
            });


README 파일 내용 받아오는 법

fetch("https://api.github.com/repos/{소유자이름}/{레포이름}/readme")
            .then((response) => response.json())
            .then((data) =>{
                console.log(data) // json 파일
                console.log(data.content) //파일 내용 base64로 받아와진다
                console.log(decodeURIComponent(atob(data.content))); //utf-8로 디코딩
            });

0개의 댓글