axios
-
async await , then catch (feat. tryCatch)axios 2023. 5. 11. 17:00
openWeather api 를 이용해 데이터를 전송받는 일을 비동기로 처리한다. 처음엔 try catch , then catch 가 뭔지 혼동스럽고 그냥 돌아가는데로 사용했는데 어떤 분덕에 확실히 이해하게 되었다. callback 지옥을 해결하기 위한 Promise 가 등장하고 Promise then ...then ...then ...then 을 조금더 편리하게 쓰기 위한 async await 가 등장했다. 이 async await 와 함께 try Catch 구문을 사용하면 에러핸들링도 가능하다! 일단 내가 작성했던 첫번째 코드를 보자 import { useEffect, useState } from "react"; import axios from "axios"; const WeatherHook = (p..
-
React 에서 axios 요청하는 법axios 2023. 2. 24. 21:19
📌 axios 는 then 이라는 문법을 통해 await async promise 를 처리하고 있다고 한다. 비동기 처리 방식이라는 것은 알겠는데 정확히 무슨 말인지는 모르겠다. 차후 공부하면 다시 써보자 ...(중략) interface CoinInterface { id : string , name : string, symbol : string, rank : number, is_new : boolean, is_active : boolean, type : string } function Coins() { // useState typescript 사용 const [coins , setCoins] = useState([]) useEffect(()=>{ axios.get('https://api.coinpapri..
-
Node.js 에서 axios 사용법 : get post put delet 및 req 로 데이터 받는 법axios 2023. 1. 30. 19:49
📌 get과 delete 는 {params : { data }} 구조로 보내고 req.query 로 받는다. 📌 post 와 put 은 { data } 구조로 보내고 req.body 로 받는다. 😥 이유 : 아직 정확하게 모르겠다. 이유를 알게되면 해당 글을 수정해야겠다 // get 요청 및 받는법 axios.get("/api/identify", {params: {email}}) router.get("/identify", async (req, res) => { const {email} = req.query; } // post 요청 및 받는법 axios.post("/api/login", {userid: userid, password: password}) router.post("/login", async (..