diff --git "a/4th/1\353\262\210/1.md" "b/4th/1\353\262\210/1.md" index 33ac183..6aec537 100644 --- "a/4th/1\353\262\210/1.md" +++ "b/4th/1\353\262\210/1.md" @@ -1,3 +1,4 @@ ## 백엔드로 필요한 데이터를 요청하기 위해 가장 필요한 2가지는? (백엔드 개발자의 문서를 통해서 확인해야 하는 2가지 입니다) (여기에 작성하세요) +API 주소와 메소드 (method)가 필요합니다. diff --git "a/4th/2\353\262\210/2.md" "b/4th/2\353\262\210/2.md" index 92c6af7..2980ab7 100644 --- "a/4th/2\353\262\210/2.md" +++ "b/4th/2\353\262\210/2.md" @@ -1,3 +1,4 @@ ## REST API의 GET 메소드에 대해 아는데로 작성해보세요. (여기에 작성하세요) +서버로부터 정보를 가져오고, 데이터를 조회할 때 사용되며, 서버의 상태나 데이터를 변경하지 않습니다. diff --git "a/4th/3\353\262\210/3.md" "b/4th/3\353\262\210/3.md" index c29c151..5175944 100644 --- "a/4th/3\353\262\210/3.md" +++ "b/4th/3\353\262\210/3.md" @@ -1,3 +1,4 @@ ## REST API의 POST 메소드에 대해 아는데로 작성해보세요. (여기에 작성하세요) +새로운 데이터를 생성하거나 리소스를 업데이트할 때 사용합니다. diff --git "a/4th/4\353\262\210/4.md" "b/4th/4\353\262\210/4.md" index 8faa387..1c32b4d 100644 --- "a/4th/4\353\262\210/4.md" +++ "b/4th/4\353\262\210/4.md" @@ -1,18 +1,18 @@ ## REST API의 의미를 고려할 때, 다음 API 주소들의 의미는 무엇일지 추측해보세요. (정답이 아니라 추측하는 겁니다) 1. `https://dummyjson.com/products` (method: GET) - - + - products의 리스트를 불러오라는 의미 2. `https://dummyjson.com/products/1` (method: GET) - - + - products의 첫번째 product를 불러오라는 의미 3. `https://dummyjson.com/products/search?q=phone` (method: GET) - - + - products에서 phone과 관련된 걸 불러오라는 의미 4. `https://dummyjson.com/products/categories` (method: GET) - - + - products의 categories를 불러오라는 의미 5. `https://dummyjson.com/products/category/smartphones` (method: GET) - - + - products의 categories에서 smartphones와 관련된걸 불러오라는 의미 6. `https://dummyjson.com/products/add` (method: POST) - - + - products에 새로운 걸 추가하겠다는 의미 7. `https://dummyjson.com/products/1` (method: PUT) - - + - products에서 첫번째 products를 수정하겠다는 의미 8. `https://dummyjson.com/products/1` (method: DELETE) - - + - products에서 첫번째 products를 삭제하겠다는 의미 diff --git "a/4th/5\353\262\210/index.js" "b/4th/5\353\262\210/index.js" index efc18d2..8231f7a 100644 --- "a/4th/5\353\262\210/index.js" +++ "b/4th/5\353\262\210/index.js" @@ -1,3 +1,28 @@ // 여기에 1번 문제의 답을 작성하세요. +const getProducts = async () => { + const res = await fetch("https://dummyjson.com/products"); + const data = await res.json(); + return data; +}; // 여기에 2번 문제의 답을 작성하세요. + +const addProduct = async () => { + try { + const response = await fetch("https://dummyjson.com/products/add", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + title: "BMW Pencil", + /* other product data */ + }), + }); + + const data = await response.json(); + console.log(data); + } catch (error) { + console.log("Error: error입니다.", error.message); + } +}; + +addProduct();