Notice
Recent Posts
Recent Comments
Link
04-30 05:35
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Archives
Today
Total
관리 메뉴

<<개발일지>>

fetch API 본문

JavaScript, TS

fetch API

개발하는지호 2023. 12. 10. 16:21

Ajax 프로그래밍 방식에서 주로 사용하던 API는 XMLHttpRequest였는데, 보다 간소화되어 사용이 조금 더 편리해진 API

 

무언가를 가져오다, 불러오다를 뜻하는 Fetch로 네이밍된 API이다.

 

기본 사용법

활용 예시

const detectLanguage = async (text) => {
let sourceLanguage;

const url = '/detectLangs';
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ query: text }),
};

await fetch(url, options)
.then(response => response.json())
.then(data => {
sourceLanguage = data.langCode;
sourceSelect.value = sourceLanguage;
})
.catch(error => console.error(error));

return sourceLanguage;
}

 

 

'JavaScript, TS' 카테고리의 다른 글

Promise 객체의 상태  (0) 2023.12.10
Promise  (0) 2023.12.10
[Express.js] express.static() 정적 파일 서비스  (1) 2023.12.03
동기와 비동기  (0) 2023.12.01
Web API (좀더 정리 필요)  (0) 2023.11.29