ํ™ˆ REST API
ํฌ์ŠคํŠธ
์ทจ์†Œ

REST API

๐Ÿ’ป REST API๋ž€?

REST๋ž€ (Representational State Transfer)์˜ ์•ฝ์ž๋กœ, ์ฃผ๊ณ ๋ฐ›๋Š” ์ž์›(resource)์— ์ด๋ฆ„์„ ๊ทœ์ •ํ•˜๊ณ  URI์— ๋ช…์‹œํ•ด HTTP ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ํ•ด๋‹น ์ž์›์˜ ์ƒํƒœ๋ฅผ ์ฃผ๊ณ ๋ฐ›๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

REST API๋Š” REST ์•„ํ‚คํ…์ฒ˜๋ฅผ ๋”ฐ๋ฅด๋Š” ์‹œ์Šคํ…œ/์—ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ธํ„ฐํŽ˜์ด์Šค๋ผ๊ณ  ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. REST ์•„ํ‚คํ…์ฒ˜๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ์›น์„œ๋น„์Šค๋ฅผ RESTful ํ•˜๋‹ค๋ผ๊ณ  ํ‘œํ˜„ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ’ป REST API์˜ ๊ทœ์น™

  • URI์˜ ๋งˆ์ง€๋ง‰์—๋Š” / ํฌํ•จํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

    โญ•๏ธ http://localhost:3000/product
    โŒ http://localhost:3000/product/

  • _๋Š” ์‚ฌ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋Œ€์‹  -๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

    โญ•๏ธ http://localhost:3000/provider-company-name
    โŒ http://localhost:3000/provider_company_name

  • URL์—๋Š” ๋™์‚ฌ๊ฐ€ ์•„๋‹Œ ๋ช…์‚ฌ๋ฅผ ํฌํ•จํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋™์‚ฌ๋Š” HTTP ๋ฉ”์†Œ๋“œ๋กœ ํ‘œํ˜„ํ•ฉ๋‹ˆ๋‹ค.

    โญ•๏ธ http://localhost:3000/product/123
    โŒ http://localhost:3000/delete-product/123

  • URI๋Š” ์†Œ๋ฌธ์ž๋กœ ์ž‘์„ฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • ํŒŒ์ผ์˜ ํ™•์žฅ์ž๋Š” URI์— ํฌํ•จํ•˜๋ฉด ์•ˆ๋ฉ๋‹ˆ๋‹ค.

    โญ•๏ธ http://localhost:3000/thumbnail
    โŒ http://localhost:3000/thumbnail.jpeg

์ด ๊ธฐ์‚ฌ๋Š” ์ €์ž‘๊ถŒ์ž์˜ CC BY 4.0 ๋ผ์ด์„ผ์Šค๋ฅผ ๋”ฐ๋ฆ…๋‹ˆ๋‹ค.

Spring annotation

์ผ๋ ‰ํŠธ๋ก  Main Process - Browser Window