async function post(host, path, body, headers = {}) {
const url = `https://${host}/${path}`;
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
...headers,
},
body: JSON.stringify(body),
};
const res = await fetch(url, options);
const data = await res.json();
if (res.ok) {
return data;
} else {
throw Error(data);
}
}
post("jsonplaceholder.typicode.com", "posts", {
title: "Test",
body: "I am testing!",
userId: 1,
})
.then((data) => console.log(data))
.catch((error) => console.log(error));
'study > java' 카테고리의 다른 글
[MyBatis] 중복 쿼리 줄여주는 sql, include, property 태그 문법 살펴보기 (0) | 2023.07.12 |
---|---|
javascript 페이징 (0) | 2023.07.05 |
jsp 지시태그 (0) | 2023.07.05 |
https://haenny.tistory.com/295 전자정부프레임워크 4.0 스프링 설정 정리 잘해 놨어 굿 (0) | 2023.03.27 |
[AWS, 웹 프로젝트] 3. STS에서 Gradle Project 생성하기[출처] [AWS, 웹 프로젝트] 3. STS에서 Gradle Project 생성하기|작성자 엠케이 (0) | 2023.03.27 |