[Spring] API์™€ REST API

API๋ž€?

ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ์„œ๋ฒ„์— ์ „๋‹ฌํ•˜๊ณ , ์„œ๋ฒ„์˜ ๊ฒฐ๊ณผ๋ฌผ์„ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์ž˜ ๋Œ๋ ค์ฃผ๋Š” ์—ญํ• 

REST API๋ž€?

์›น์˜ ์žฅ์ ์„ ์ตœ๋Œ€ํ•œ ํ™œ์šฉํ•˜๋Š” API

  • REST : Representational State Transfer : ์ž์›์„ ์ด๋ฆ„์œผ๋กœ ๊ตฌ๋ถ„ํ•ด ์ž์›์˜ ์ƒํƒœ๋ฅผ ์ฃผ๊ณ ๋ฐ›๋Š” API
  • REST API : URL์˜ ์„ค๊ณ„ ๋ฐฉ์‹

REST API์˜ ํŠน์ง•

  • ์„œ๋ฒ„/ํด๋ผ์ด์–ธํŠธ ๊ตฌ์กฐ
  • ๋ฌด์ƒํƒœ
  • ์บ์‹œ ์ฒ˜๋ฆฌ ๊ฐ€๋Šฅ
  • ๊ณ„์ธตํ™”
  • ์ธํ„ฐํŽ˜์ด์Šค ์ผ๊ด€์„ฑ

REST API์˜ ์žฅ๋‹จ์ 

  • ์žฅ์ 
    • URL๋งŒ ๋ณด๊ณ ๋„ ๋ฌด์Šจ ํ–‰๋™์„ ํ•˜๋Š” API์ธ์ง€ ๋ช…ํ™•
    • ์ƒํƒœ๊ฐ€ ์—†์Œ : ํด๋ผ์ด์–ธํŠธ์™€ ์„œ๋ฒ„์˜ ์—ญํ• ์ด ๋ช…ํ™•ํ•˜๊ฒŒ ๋ถ„๋ฆฌ
    • HTTP ํ‘œ์ค€์„ ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋“  ํ”Œ๋žซํผ์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅ
  • ๋‹จ์ 
    • HTTP ๋ฉ”์„œ๋“œ ๊ฐœ์ˆ˜์˜ ์ œํ•œ
    • ์„ค๊ณ„๋ฅผ ํ•˜๊ธฐ ์œ„ํ•ด ๊ณต์‹์ ์œผ๋กœ ์ œ๊ณต๋˜๋Š” ํ‘œ์ค€ ๊ทœ์•ฝ์ด ์กด์žฌํ•˜์ง€ ์•Š์Œ

REST API๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฒ•

๊ทœ์น™ 1. URL์—๋Š” ๋™์‚ฌ๋ฅผ ์“ฐ์ง€ ๋ง๊ณ , ์ž์›์„ ํ‘œ์‹œํ•ด์•ผ ํ•œ๋‹ค

  • /student/1
  • /article/1
  • RESTful API ์„ค๊ณ„์‹œ ๋™์‚ฌ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Œ

๊ทœ์น™ 2. ๋™์‚ฌ๋Š” HTTP ๋ฉ”์„œ๋“œ๋กœ

  • GET, POST, PUT, DELETE ๋“ฑโ€ฆ
์„ค๋ช… ์ ํ•ฉํ•œ HTTP ๋ฉ”์„œ๋“œ์™€ URL
id๊ฐ€ 1์ธ ๋ธ”๋กœ๊ทธ ๊ธ€์„ ์กฐํšŒํ•˜๋Š” API GET/articles/1
๋ธ”๋กœ๊ทธ ๊ธ€์„ ์ถ”๊ฐ€ํ•˜๋Š” API POST/articles/1
๋ธ”๋กœ๊ทธ ๊ธ€์„ ์ˆ˜์ •ํ•˜๋Š” API PUT/articles/1
๋ธ”๋กœ๊ทธ ๊ธ€์„ ์‚ญ์ œํ•˜๋Š” API DELETE/articles/1

Categories:

Updated:

Leave a comment