Web programming

Web programming : RESTful API ๋ž€

ํ”„๋กœ๊ทธ๋ž˜๋จธ ์˜ค์›” 2023. 12. 12.

 

RESTful API๋ž€ ๋ฌด์—‡์ธ๊ฐ€์š”?

RESTful API๋Š” ๋‘ ์ปดํ“จํ„ฐ ์‹œ์Šคํ…œ์ด ์ธํ„ฐ๋„ท์„ ํ†ตํ•ด ์ •๋ณด๋ฅผ ์•ˆ์ „ํ•˜๊ฒŒ ๊ตํ™˜ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค์ž…๋‹ˆ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ๋น„์ฆˆ๋‹ˆ์Šค ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ๋‹ค์–‘ํ•œ ํƒœ์Šคํฌ๋ฅผ ์ˆ˜ํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค๋ฅธ ๋‚ด๋ถ€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐ ์„œ๋“œ ํŒŒํ‹ฐ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๊ณผ ํ†ต์‹ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์›”๊ฐ„ ๊ธ‰์—ฌ ๋ช…์„ธ์„œ๋ฅผ ์ƒ์„ฑํ•˜๋ ค๋ฉด ์ธ๋ณด์ด์Šค ๋ฐœํ–‰์„ ์ž๋™ํ™”ํ•˜๊ณ  ๋‚ด๋ถ€์˜ ๊ทผ๋ฌด ์‹œ๊ฐ„ ๊ธฐ๋ก ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๊ณผ ํ†ต์‹ ํ•˜๊ธฐ ์œ„ํ•ด ๋‚ด๋ถ€ ๊ณ„์ • ์‹œ์Šคํ…œ์ด ๋ฐ์ดํ„ฐ๋ฅผ ๊ณ ๊ฐ์˜ ๋ฑ…ํ‚น ์‹œ์Šคํ…œ๊ณผ ๊ณต์œ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. RESTful API๋Š” ์•ˆ์ „ํ•˜๊ณ  ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ํšจ์œจ์ ์ธ ์†Œํ”„ํŠธ์›จ์–ด ํ†ต์‹  ํ‘œ์ค€์„ ๋”ฐ๋ฅด๋ฏ€๋กœ ์ด๋Ÿฌํ•œ ์ •๋ณด ๊ตํ™˜์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
์ถœ์ฒ˜ : https://aws.amazon.com/ko/what-is/restful-api/

 

 

REST์˜ ๊ตฌ์„ฑ์š”์†Œ

โญ REST๋Š” ์ž์›, ํ–‰์œ„, ํ‘œํ˜„์œผ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค.

์ž์›(Resource)๋Š” URI๊ฐ€ ๊ฐ€๋ฆฌํ‚ค๋Š” ๋ฆฌ์†Œ์Šค
ํ–‰์œ„(Verb)๋Š” HTTP Method
ํ‘œํ˜„(Representation)์€ ๋ฆฌ์†Œ์Šค์˜ ํŠน์ • ์‹œ์  ์ƒํƒœ๋ฅผ ๋ฐ˜์˜ํ•˜๊ณ  ์žˆ๋Š” ์ •๋ณด

REST๋Š” URI๋ฅผ ํ†ตํ•ด ์ž์›์„ ํ‘œ์‹œํ•˜๊ณ  HTTP Method๋ฅผ ์ด์šฉํ•˜์—ฌ ํ•ด๋‹น ์ž์›์˜ ํ–‰์œ„๋ฅผ ์ •ํ•ด์ฃผ๋ฉฐ ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ›๋Š” ๊ฒƒ์„ ๋งํ•œ๋‹ค.

 

1๏ธโƒฃ์ž์› - HTTP URI

Ex) ํšŒ์› DB์—์„œ, 8๋ฒˆ์งธ ํšŒ์›์„ ๊ฐ€๋ฆฌํ‚ค๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ '/member/8'๋กœ ํ‘œํ˜„

 

2๏ธโƒฃํ–‰์œ„ - HTTP Method

REST API๋Š” HTTP ํ”„๋กœํ† ์ฝœ์˜ ์ธํ”„๋ผ๋ฅผ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ํ–‰์œ„์—์„œ๋„ HTTP Method๋ฅผ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•œ๋‹ค.

 

    ๐ŸšฉHttp Method ์ •๋ฆฌ!
    GET		- ๋ฆฌ์†Œ์Šค์— ๋Œ€ํ•œ ์ •๋ณด ๊ฒ€์ƒ‰
    POST	- ๋ฆฌ์†Œ์Šค ์ƒ์„ฑ
    PUT		- ๋ฆฌ์†Œ์Šค ์—…๋ฐ์ดํŠธ
    DELETE	- ๋ฆฌ์†Œ์Šค ๋˜๋Š” ๊ด€๋ จ ๊ตฌ์„ฑ ์š”์†Œ ์‚ญ์ œ

์ถ”๊ฐ€์ ์œผ๋กœ ๋ฆฌ์†Œ์Šค ์ˆ˜์ •์—๋Š” PATCH ๋„ ์žˆ๋‹ค.

 

PATCH ๋Š” ๋ฆฌ์†Œ์Šค์˜ ์ •๋ณด๋ฅผ ์ผ๋ถ€๋ถ„์„ ์ˆ˜์ •ํ•˜๋Š” ๊ฒƒ์ด๊ณ , PUT ์€ ๋ฆฌ์†Œ์Šค๋ฅผ ์ƒˆ๋กœ์šด ๊ฐ์ฒด๋กœ ๊ฐˆ์•„์น˜์šฐ๋Š” ๊ฒƒ์ด๋‹ค.

 

3๏ธโƒฃํ‘œํ˜„ - HTTP Message Payload

Client์™€ Server๊ฐ€ ๋ฆฌ์†Œ์Šค๋ฅผ ์ฃผ๊ณ ๋ฐ›๋Š” ํ˜•ํƒœ๋กœ JSON, XML๋“ฑ์˜ ํ˜•์‹์œผ๋กœ ์ฃผ๊ณ  ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค.

๐ŸšฉPAYLOAD๋ž€? ์ „์†ก๋˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์˜๋ฏธํ•œ๋‹ค.

 

 

์ฐธ๊ณ 

https://velog.io/@yoojkim/Rest-API-RESTful%ED%95%98%EA%B2%8C-URL-%EC%84%A4%EA%B3%84%ED%95%98%EA%B8%B0

๋Œ“๊ธ€