npm i axios
const baseURL: "https://songbetter.tommy.com/"
// GET
axios.get(baseURL).then(response => console.log(response.data))
// POST (= PUT과 동일한 방법)
axios.post(`${baseURI}/1`, {/*body*/}, {headers:{/**/}).then(response => console.log(response.data)
// DELETE
axios.delete(`${baseURI}/1`).then(() => alert("POST DELETED!"))
// Erros Handling
.catch(error => console.log(error))
const client = axios.create({
baseURL: "https://songbetter.tommy.com/"
});
client.get("/1").then(response => console.log(response.data))
useEffect(() => {
async function getPosts() {
const response = await client.get("/1");
console.log(response.data);
}
getPosts();
}, []);
async function deletePost() {
await client.delete("/1");
alert("POST DELETED!")
}
npm i use-axios-client
const { data, error, loading } = useAxios({
url: "https://songbetter.tommy.com/1"
});