TIL74. HTTP : REST API ๋ž€?

ID์งฑ์žฌยท2021๋…„ 11์›” 6์ผ
0

HTTP

๋ชฉ๋ก ๋ณด๊ธฐ
12/17
post-thumbnail
post-custom-banner

๐Ÿ“Œ ์ด ํฌ์ŠคํŒ…์—์„œ๋Š” HTTP์˜ REST API์˜ ๊ฐœ๋…์— ๋Œ€ํ•ด ์ •๋ฆฌํ•˜์˜€์Šต๋‹ˆ๋‹ค.



๐ŸŒˆ REST API ๋ž€?

๐Ÿ”ฅ REST API ๋ž€?

๐Ÿ”ฅ REST API ์„ค๊ณ„ ๊ทœ์น™



1. REST API ๋ž€?

๐Ÿค” RESTful API์ด ๋งž์„๊นŒ? REST API๊ฐ€ ๋งž์„๊นŒ?

โœ”๏ธ ful์ด๋ž€ Statless์™€ Stateful๊ณผ ๊ฐ™์ด ful์ด ๋ถ™์œผ๋ฉด "~ํ•œ", "~์Šค๋Ÿฌ์šด", "~๋‹ค์šด" ์˜๋ฏธ๋กœ ํ•ด์„ํ•˜๋ฉด ๋œ๋‹ค. ์ด์— RESTful API๋Š” "RESTํ•œ API", "REST ๋‹ค์šด" ์ •๋„๋กœ ํ•ด์„ํ•  ์ˆ˜ ์žˆ๋‹ค.

โœ”๏ธ ์ฆ‰, REST์˜ ์›๋ฆฌ ๋˜๋Š” REST์˜ ํ˜•์‹์„ ๊ฐ–์ถฐ ์„ค๊ณ„๋œ ์‹œ์Šคํ…œ์„ RESTfulํ•˜๋‹ค ํ•˜๊ณ , ์ด์— REST API๋ฅผ ์ œ๊ณตํ•˜๋Š” ์›น ์„œ๋น„์Šค๋ฅผ RESTful ํ•˜๋‹ค๊ณ  ํ•  ์ˆ˜ ์žˆ๋‹ค.

๐Ÿค” ๊ทธ๋Ÿผ REST ๋ž€?

โœ”๏ธ REST๋Š” "Representational State Transfer"์˜ ์•ฝ์ž์ด๋‹ค. ๊ทผ๋ฐ RST์ด์ง€ ์™œ REST๋ƒ ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ์ด์œ ๋Š” ๋ชจ๋ฅธ๋‹ค. Representational์—์„œ RE๋ฅผ ๋”ฐ์™”๋‹ค.

โœ”๏ธ ๊ทธ๋Ÿผ REST๋ž€ ๊ฒƒ์ด ๋ฌด์—‡์ธ๊ฐ€. REST๋Š” HTTP URI๋ฅผ ํ†ตํ•ด ์ž์›(Resource)์„ ๋ช…์‹œํ•˜๊ณ , HTTP Method๋ฅผ ํ†ตํ•ด ์ž์›์— ๋Œ€ํ•œ ํ–‰์œ„๋ฅผ ์ ์šฉํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค.

๐Ÿค” ๊ทธ๋ž˜์„œ REST API ๋ž€?

โœ”๏ธ "์‚ฌ๋žŒ์ด ์ธ์ง€ํ•˜๊ธฐ ์‰ฝ๊ฒŒ ์ž์›๊ณผ ์ƒํƒœ๋ฅผ ํ‘œํ˜„ํ•œ API"์ด๋‹ค. ๊ฒฐ๊ตญ REST API๋Š” ์–ด๋–ค ๊ธฐ์ˆ ์ด ์•„๋‹ˆ๋ผ ํ˜•์‹์ด๋ฉฐ API๊ฐ€ RESTํ•œ ํ˜•์‹์„ ๋”ฐ๋ž์„ ๋•Œ, REST API๋ผ ํ•  ์ˆ˜ ์žˆ๋‹ค.

โœ”๏ธ ์ด์— REST(Representational State Transfer)์€ API๋Š” HTTP ํ”„๋กœํ† ์ฝœ์„ ์ด์šฉํ•ด์„œ ์ž์›์˜ ํ–‰์œ„๋Š” HTTP ๋งค์„œ๋“œ๋กœ ํ‘œํ˜„ํ•˜๊ณ , URI๊ฐ€ ์ž์›์„ ์‹๋ณ„ํ•  ์ˆ˜ ์žˆ๊ฒŒ ์„ค๊ณ„๋œ ํ˜•์‹์„ ์˜๋ฏธํ•œ๋‹ค.

โœ”๏ธ RESTful API๋Š” ๊ทธ ์ž์ฒด๋กœ๋งŒ์œผ๋กœ๋„ API ๋ชฉ์ ์ด ์‰ฝ๊ฒŒ ์ดํ•ด๋œ๋‹ค๋Š” ์žฅ์ ์ด ์žˆ์œผ๋‚˜, ํ‘œ์ค€ ๊ทœ์•ฝ์ด ์—†๊ธฐ ๋•Œ๋ฌธ์— ์•ˆํ‹ฐํŒจํ„ด(์‹ค์ œ ๋งŽ์ด ์‚ฌ์šฉ๋˜๋Š” ํŒจํ„ด์ด์ง€๋งŒ ๋น„ํšจ์œจ์ ์ด๊ฑฐ๋‚˜ ๋น„์ƒ์ ์ธ ํŒจํ„ด)์œผ๋กœ ์ž‘์„ฑ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ํ”ํ•˜๋‹ค.



2. REST API ์„ค๊ณ„ ๊ทœ์น™

๐Ÿค” URI๋Š” ์ž์›์„ ๋ช…ํ™•ํ•˜๊ฒŒ ํ‘œํ˜„ํ•ด์•ผ ํ•œ๋‹ค.

โœ”๏ธ resource๋Š” ๋™์‚ฌ๋ณด๋‹ค๋Š” ๋ช…์‚ฌ๋ฅผ, ๋Œ€๋ฌธ์ž๋ณด๋‹ค๋Š” ์†Œ๋ฌธ์ž๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
โœ”๏ธ resource์˜ ๋„ํ๋จผํŠธ ์ด๋ฆ„์œผ๋กœ๋Š” ๋‹จ์ˆ˜ ๋ช…์‚ฌ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.
โœ”๏ธ resource์˜ ์ปฌ๋ ‰์…˜ ์ด๋ฆ„์œผ๋กœ๋Š” ๋ณต์ˆ˜ ๋ช…์‚ฌ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.
โœ”๏ธ resource์˜ ์Šคํ† ์–ด ์ด๋ฆ„์œผ๋กœ๋Š” ๋ณต์ˆ˜ ๋ช…์‚ฌ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.

๐Ÿค” ์ž์›์— ๋Œ€ํ•œ ํ–‰์œ„๋Š” HTTP Method๋กœ ๋Œ€์‹ ํ•œ๋‹ค.

โœ”๏ธ ์ž์›์— ๋Œ€ํ•œ ํ–‰์œ„๋Š” HTTP Method(GET, PUT, POST, DELETE ๋“ฑ)๋กœ ํ‘œํ˜„ํ•œ๋‹ค.

GET /members/delete/1 ๐Ÿ‘ˆ REST API๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ
GET /members/1 ๐Ÿ‘ˆ REST API์˜ ๊ทœ์น™์„ ๋”ฐ๋ฅธ ๊ฒฝ์šฐ

โœ”๏ธ ์ด์— ์ž์›์— ํ–‰์œ„๋กœ์จ ๋™์‚ฌ ํ‘œํ˜„์€ ๋ถˆ๊ฐ€ํ”ผํ•œ ๊ฒฝ์šฐ๋ฅผ ์ œ์™ธํ•˜๊ณ  URL์— ๋“ค์–ด๊ฐ€๋ฉด ์•ˆ๋œ๋‹ค.

๐Ÿค” ์Šฌ๋Ÿฌ์‹œ, ํ•˜์ดํ”ˆ, ์–ธ๋”๋ฐ” ๊ทœ์น™

โœ”๏ธ ์Šฌ๋ž˜์‹œ ๊ตฌ๋ถ„์ž(/)๋Š” ์ž์›์˜ ๊ณ„์ธต ๊ด€๊ณ„๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š”๋ฐ ์‚ฌ์šฉํ•œ๋‹ค. URI ๋งˆ์ง€๋ง‰์—๋Š” ์Šฌ๋ž˜์‹œ(/)๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.
โœ”๏ธ ๋ถˆ๊ฐ€ํ”ผํ•˜๊ฒŒ ๊ธด URI๊ฒฝ๋กœ๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด ํ•˜์ดํ”ˆ์„ ์‚ฌ์šฉํ•ด ๊ฐ€๋…์„ฑ์„ ๋†’์ธ๋‹ค.
โœ”๏ธ ๋ฐ‘์ค„์€ ๋ณด๊ธฐ ์–ด๋ ต๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.

profile
Keep Going, Keep Coding!
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€