Recent Posts
Recent Comments
Link
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

kohigowild

REST API๊ฐ€ ๋จผ๋ฐ์š”... ๋ณธ๋ฌธ

mitmitwiki

REST API๊ฐ€ ๋จผ๋ฐ์š”...

kohi โ˜• 2023. 4. 11. 17:05

๐Ÿ“ก REST

Representational State Transfer
- ์ž์› (Resource) : URI
- ํ–‰์œ„ (Verb) : HTTP Method
- ํ‘œํ˜„ (Representations) : Server ์‘๋‹ต

HTTP URI๋ฅผ ํ†ตํ•ด ์ž์›์„ ๋ช…์‹œํ•˜๊ณ  HTTP Method(POST, GET, PUT, DELETE)๋ฅผ ํ†ตํ•ด ํ•ด๋‹น ์ž์›์— ๋Œ€ํ•œ CRUD Operation์„ ์ ์šฉํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค. ์ฆ‰, REST๋Š” ์ž์› ๊ธฐ๋ฐ˜์˜ ๊ตฌ์กฐ ์„ค๊ณ„์˜ ์ค‘์‹ฌ์— Resource๊ฐ€ ์žˆ๊ณ , HTTP Method๋ฅผ ํ†ตํ•ด Resource๋ฅผ ์ฒ˜๋ฆฌํ•˜๋„๋ก ์„ค๊ณ„๋œ ์•„ํ‚คํ…์ฒ˜๋ฅผ ์˜๋ฏธํ•œ๋‹ค.

 

์˜ํ™”๋ฅผ ๊ฒ€์ƒ‰ํ•˜๋Š” ์‚ฌ์ดํŠธ๊ฐ€ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ–ˆ์„ ๋•Œ

  • /createMovie
  • /seeMovie
  • /getMovie/inception
  • /deleteMovie/inception
  • /updateMovie/inception
  • /getTopRatedMovies
  • /findMoviesFromThisYear

API๋ฅผ ์ด๋ ‡๊ฒŒ ์„ค๊ณ„ํ•˜๋Š” ๊ฒฝ์šฐ ๋ช…ํ™•ํ•œ ํŒจํ„ด์ด ์—†๊ธฐ ๋•Œ๋ฌธ์— ํŒ€์›๋“ค์ด ์ดํ•ดํ•˜๊ธฐ ํž˜๋“ค๋‹ค. ํ‘œ์ค€์ด ์—†๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ํ‘œ์ค€์ด ์žˆ๊ธฐ ์œ„ํ•ด์„œ๋Š” URL์—์„œ ๋™์‚ฌ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ๋ช…์‚ฌ๋งŒ ๋‚จ๊ธด๋‹ค.

Movies

Inception (unique identifier)

 

  • /movies
  • /movies/inception

 

ํ•ด๋‹น API URI์— HTTP method๋ฅผ ๊ฒฐํ•ฉํ•œ๋‹ค.

๐Ÿ’ก HTTP method

GET ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ๋ฐ์ดํ„ฐ ์ทจ๋“
POST ์„œ๋ฒ„์— ๋ฐ์ดํ„ฐ ์ถ”๊ฐ€, ์ž‘์„ฑ
PUT ์„œ๋ฒ„์˜ ๋ฐ์ดํ„ฐ ๊ฐฑ์‹ , ์ž‘์„ฑ
DELETE ์„œ๋ฒ„์˜ ๋ฐ์ดํ„ฐ ์‚ญ์ œ

 

  • GET /movies : ๋ชจ๋“  ์˜ํ™” ๋ฆฌ์ŠคํŠธ๋ฅผ ์ทจ๋“ํ•œ๋‹ค.
  • POST /movies : ์˜ํ™” ๋ฆฌ์ŠคํŠธ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.
  • GET /movies/inception : ์ธ์…‰์…˜์˜ ์ •๋ณด๋ฅผ ์ทจ๋“ํ•œ๋‹ค.
  • PUT /movies/inception : ์ธ์…‰์…˜์˜ ์ •๋ณด๋ฅผ ๋ณ€๊ฒฝํ•œ๋‹ค.
  • DELETE /movies/inception : ์ธ์…‰์…˜์„ ์‚ญ์ œํ•œ๋‹ค.

 

๊ฒ€์ƒ‰์ด๋‚˜ ํ•„ํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ํŽ˜์ด์ง€๋„ค์ด์…˜๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.

  • /movies?min_rating=9.8
  • /movies?release_date=2021
  • /movies?pageNum=2&size=8

 

๐Ÿ“ก REST์˜ ํŠน์ง•

  • Server - Client ๊ตฌ์กฐ
    • ์ž์›์ด ์žˆ๋Š” ์ชฝ์ด ์„œ๋ฒ„, ์ž์›์„ ์š”์ฒญํ•˜๋Š” ์ชฝ์ด ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋œ๋‹ค.
  • Stateless
    • ์ด์ „์˜ ์š”์ฒญ์ด ๋‹ค์Œ์˜ ์š”์ฒญ์— ์—ฐ๊ด€๋˜์ง€ ์•Š๋Š”๋‹ค. ์„ธ์…˜ ์ •๋ณด๋‚˜ ์ฟ ํ‚ค ์ •๋ณด๋ฅผ ๋ณ„๋„๋กœ ์ €์žฅํ•˜๊ณ  ๊ด€๋ฆฌํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— API ์„œ๋ฒ„๋Š” ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ๋งŒ์„ ๋‹จ์ˆœํžˆ ์ฒ˜๋ฆฌํ•œ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ์„œ๋ฒ„์˜ ์ฒ˜๋ฆฌ ๋ฐฉ์‹์— ์ผ๊ด€์„ฑ์„ ๋ถ€์—ฌํ•˜๊ณ  ๋ถˆํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ๊ด€๋ฆฌํ•˜์ง€ ์•Š์Œ์œผ๋กœ์จ ๊ตฌํ˜„์ด ๋‹จ์ˆœํ•ด์ง„๋‹ค.
  • Cacheable
    • HTTP์˜ ์บ์‹ฑ ๊ธฐ๋Šฅ์„ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
  • Uniform Interface
    • URI๋กœ ์ง€์ •ํ•œ ๋ฆฌ์†Œ์Šค์— ๋Œ€ํ•œ ์กฐ์ž‘์„ ํ†ต์ผ๋˜๊ณ  ํ•œ์ •์ ์ธ ์ธํ„ฐํŽ˜์ด์Šค๋กœ ์ˆ˜ํ–‰ํ•˜๋Š” ์•„ํ‚คํ…์ฒ˜ ์Šคํƒ€์ผ
  • ์ž์ฒด ํ‘œํ˜„ ๊ตฌ์กฐ
    • REST API ๋ฉ”์‹œ์ง€๋งŒ ๋ณด๊ณ ๋„ ์ด๋ฅผ ์‰ฝ๊ฒŒ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋Š” ์ž์ฒด ํ‘œํ˜„ ๊ตฌ์กฐ
  • ๊ณ„์ธตํ˜• ๊ตฌ์กฐ
    • REST ์„œ๋ฒ„๋Š” ๋‹ค์ค‘ ๊ณ„์ธต์œผ๋กœ ๊ตฌ์„ฑ๋  ์ˆ˜ ์žˆ์œผ๋ฉฐ ๋ณด์•ˆ, ๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ, ์•”ํ˜ธํ™” ๊ณ„์ธต์„ ์ถ”๊ฐ€ํ•ด ๊ตฌ์กฐ์ƒ์˜ ์œ ์—ฐ์„ฑ์„ ๋‘˜ ์ˆ˜ ์žˆ๊ณ , Proxy, ๊ฒŒ์ดํŠธ์›จ์ด ๊ฐ™์€ ๋„คํŠธ์›Œํฌ ๊ธฐ๋ฐ˜์˜ ์ค‘๊ฐ„ ๋งค์ฒด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•œ๋‹ค.

 

๐Ÿ“ก REST์˜ ์žฅ์ 

  • REST API ๋ฉ”์‹œ์ง€๋ฅผ ์ฝ๋Š” ๊ฒƒ๋งŒ์œผ๋กœ๋„ ๋ฉ”์‹œ์ง€๊ฐ€ ์˜๋„ํ•˜๋Š” ๋ฐ”๋ฅผ ๋ช…ํ™•ํ•˜๊ฒŒ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค.
    • Statelessํ•œ ํŠน์ง• ๋•Œ๋ฌธ์— ํ•ด๋‹น URI์™€ ์›ํ•˜๋Š” ๋ฉ”์„œ๋“œ ์ž์ฒด๋งŒ ๋…๋ฆฝ์ ์œผ๋กœ ์ดํ•ดํ•˜๋ฉด ๋จ
  • ํด๋ผ์ด์–ธํŠธ์™€ ์„œ๋ฒ„์˜ ์—ญํ• ์ด ๋ช…ํ™•ํ•˜๊ฒŒ ๋ถ„๋ฆฌ๋˜์–ด ์žˆ์–ด ์—…๋ฌด๋Ÿ‰ ๊ฐ์†Œ, ํ”Œ๋žซํผ ๋…๋ฆฝ์„ฑ ํ™•์žฅ์˜ ํšจ๊ณผ
  • ํ—ค๋” ๋ถ€๋ถ„์— URI ์ฒ˜๋ฆฌ ๋ฉ”์„œ๋“œ๋ฅผ ๋ช…์‹œํ•จ์œผ๋กœ์จ, ํ•„์š”ํ•œ ์‹ค์ œ ๋ฐ์ดํ„ฐ๋ฅผ ํŽ˜์ด๋กœ๋“œ(๋ฐ”๋””)์— ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•œ๋‹ค.
    • ํŠน์ • ๋ฉ”์„œ๋“œ์˜ ์„ธ๋ถ€์ ์ธ ํ‘œํ˜„ ๋ฌธ๊ตฌ๋ฅผ JSON, XML ๋“ฑ ๋‹ค์–‘ํ•œ ์–ธ์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์žฅ์ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ, ๊ฐ„๊ฒฐํ•œ ํ—ค๋” ํ‘œํ˜„์„ ํ†ตํ•œ ๊ฐ€๋…์„ฑ ํ–ฅ์ƒ์ด๋ผ๋Š” ํšจ๊ณผ๊ฐ€ ์žˆ๋‹ค.

 

๐Ÿ“ก REST์˜ ๋‹จ์ 

  • ๋ฉ”์„œ๋“œ ํ˜•ํƒœ๊ฐ€ ์ œํ•œ์ ์ด๋‹ค.
  • ๊ณต์‹ํ™”๋œ API ๋””์ž์ธ ๊ฐ€์ด๋“œ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค.

 

๐Ÿ“ก Reference

 

RESTful API๋ž€ ๋ฌด์—‡์ธ๊ฐ€์š”? - RESTful API ์„ค๋ช… - AWS

Amazon API Gateway๋Š” ์–ด๋–ค ๊ทœ๋ชจ์—์„œ๋“  ๊ฐœ๋ฐœ์ž๊ฐ€ API๋ฅผ ์†์‰ฝ๊ฒŒ ์ƒ์„ฑ, ๊ฒŒ์‹œ, ์œ ์ง€ ๊ด€๋ฆฌ, ๋ชจ๋‹ˆํ„ฐ๋ง ๋ฐ ๋ณด์•ˆ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ์™„์ „๊ด€๋ฆฌํ˜• ์„œ๋น„์Šค์ž…๋‹ˆ๋‹ค. API Gateway๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์‹ค์‹œ๊ฐ„ ์–‘๋ฐฉํ–ฅ ํ†ต์‹  ์• 

aws.amazon.com

 

REST API์˜ ์žฅ์ , ๊ทธ๋ฆฌ๊ณ  ๋‹จ์ 

์ด๋ฒˆ ๊ธ€์€ REST API์˜ ์žฅ๋‹จ์ ์— ๋Œ€ํ•ด ์กฐ๊ธˆ ๋” ์ž์„ธํžˆ ์•Œ์•„๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฏธ ์žฅ์ ๋งŒ ๋„˜์น˜๋Š” ์™„์„ฑ๋œ ๊ธฐ์ˆ ์ด๋ผ๊ณ  ๋Š๊ปด์ง€๋Š” REST API๋„ ์•„์ง ๊ฐœ์„ ๋˜์–ด์•ผ ํ•˜๋Š” ๋ถ€๋ถ„์ด ๊ต‰์žฅํžˆ ๋งŽ์€ ๋ฌธ์ œ์•„๋ผ๋Š” ๊ฒƒ์„ ์•„

wallees.wordpress.com