Server
ํ์ต ํค์๋
Express ์ด์ฉํ ๊ฐ๋จํ Server ๊ตฌ์ถ
Fetch API
Axios
Express ์ด์ฉํ ๊ฐ๋จํ Server ๊ตฌ์ถ
ํ์ํ ํจํค์ง ์ค์น
cors
express
nodemon
uuid
Server ๊ตฌ๋ ๋ฐฉ๋ฒ
ํด๋น ๋ฐฉ์์ ์์ ์ฌํญ์ ๋ฐ์ํด์ฃผ์ง ์์, server off ํ๊ณ ์ฌ๊ตฌ๋
nodemon์ server.js์ ์์ ์ฌํญ์ ๊ฐ์งํด์ ๋ฐ๋ก ๋ฐ์ํด์ฃผ๊ธฐ ๋๋ฌธ์ ์ฌ์ฉ
๐ API๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์ ์์์ผ ํ๋ ๊ฐ๋
์น๋ธ๋ผ์ฐ์ ์ ์๋ฒ์ ํต์ ํ๊ธฐ์ํด์ HTTP ํ๋กํ ์ฝ์ ์ฌ์ฉ
HTTP Protocol : TCP/IP ๊ธฐ๋ฐ์ผ๋ก ํด๋ผ์ด์ธํธ์ ์๋ฒ ์ฌ์ด์ ์ด๋ฃจ์ด์ง๋ ์์ฒญ/์๋ต ํ๋กํ ์ฝ
TCP/IP ๊ธฐ๋ฐ์ผ๋ก ํด๋ผ์ด์ธํธ์ ์๋ฒ ์ฌ์ด์ ์ด๋ฃจ์ด์ง๋ ์์ฒญ/์๋ต ํ๋กํ ์ฝ
HTTP : TCP/IP
QUIC : UDP ๊ธฐ๋ฐ์ผ๋ก ๋น ๋ฅธ ์ ์ก ์๋๋ฅผ ๊ฐ์ง๋ ํ๋กํ ์ฝ
HTTP Method : GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD, TRACE
GET : ๋ฐ์ดํฐ๋ฅผ ์์ฒญํ๊ธฐ ์ํด ์ฌ์ฉ๋๋ ๋ฉ์๋ โ ๋ณด์์ ์ฝํจ
POST : ๋ฐ์ดํฐ๋ฅผ ์์ฑํ๊ธฐ ์ํด ์ฌ์ฉ๋๋ ๋ฉ์๋ โ ๋ณด์์ ์์ ์ฑ ๋์
PUT : ๋ฐ์ดํฐ๋ฅผ ์ ๋ฐ์ดํธํ๊ธฐ ์ํด ์ฌ์ฉ๋๋ ๋ฉ์๋ โ ๋ฐ์ดํฐ๋ฅผ
์ ์ฒด์ ์ผ๋ก
์ ๋ฐ์ดํธPATCH : ๋ฐ์ดํฐ๋ฅผ ์ ๋ฐ์ดํธํ๊ธฐ ์ํด ์ฌ์ฉ๋๋ ๋ฉ์๋ โ ๋ฐ์ดํฐ๋ฅผ
์ผ๋ถ๋ถ๋ง
์ ๋ฐ์ดํธDELETE : ๋ฐ์ดํฐ๋ฅผ ์ญ์ ํ๊ธฐ ์ํด ์ฌ์ฉ๋๋ ๋ฉ์๋
Http/Https : Https(๋ณด์ ์ธ์ฆ์๊ฐ ์ถ๊ฐ๋ ํ๋กํ ์ฝ) โ ์ธํ๋ผ ์์ญ
๐ค RESTful, REST ํธ์ถํ๋ค๋ผ๋ ์๋ฏธ๋? HTTP Method๋ฅผ ๊ท์น์ ๋ง๋ API ์ค๊ณ ์ ๋ต
๐ฉ๐ปโ๐ป TodoList์ API ์์ฑ
GET : Todos ์กฐํ
POST : Todo ์์ฑ
PATCH : Todo Completed Update
PUT : Todo Task Update
DELETE : ํ ์ผ ์ญ์
Fetch API
CORS
ํด๊ฒฐํ๋ ์ฃผ์ฒด๋ Backend (๊ทผ๋ณธ)
๐จ Access to fetch at 'http://localhost:4000/todos' from origin 'http://localhost:5173' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
ํ์ต์ ๋ชฉ์ ์์ผ๋ก, Express ๋ฏธ๋ค์จ์ด๋ก ํด๊ฒฐ
GET
๊ธฐ๋ณธ ์ฌ์ฉ๋ฒ
async/await ๊ณผ ํจ๊ป ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ
POST
PATCH
DELETE
Axios
์ค์น
๐ง ๋ฉด์ ์ง๋ฌธ : ๋๋ค http ๋ฆฌํ์คํธ๋ฅผ ๋ง๋๋๊ฑด ๋์ผํ๋ค. fetch API ๋ด์ฅ ํจ์์ด๊ณ , axios๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ด๊ธฐ ๋๋ฌธ์ fetch API ๋ณด๋ค ๋ ๋์ ๋ฒ์๋ฅผ ์ปค๋ฒ ํ ์ ์๋ค. (์ฌ์ฉ์ ์์ด ํธ์์ฑ์ ์ ๊ณตํ๋ ์ฅ์ ์ด ์๋ค.)
GET
POST
Patch
Delete
Last updated