Rest API

REST API๋ž€?

REST(Representational State Transfer)๋Š” ์›น์ด HTTP ์„ค๊ณ„์ƒ ์šฐ์ˆ˜์„ฑ์„ ์ œ๋Œ€๋กœ ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•˜๊ณ  ์žˆ๋Š” ์ƒํ™ฉ์„ ๋ณด๊ณ  ์›น์˜ ์žฅ์ ์„ ์ตœ๋Œ€ํ•œ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์•„ํ‚คํ…์ณ๋กœ์„œ REST๋ฅผ ์†Œ๊ฐœํ•˜์˜€๊ณ , ์ด๋Š” HTTP ํ”„๋กœํ† ์ฝœ์„ ์˜๋„์— ๋งž๊ฒŒ ๋””์ž์ธํ•˜๋„๋ก ์œ ๋„ํ•˜๊ณ  ์žˆ๋‹ค. REST์˜ ๊ธฐ๋ณธ ์›์น™์„ ์„ฑ์‹คํžˆ ์ง€ํ‚จ ์„œ๋น„์Šค ๋””์ž์ธ์„ RESTful์ด๋ผ ํ‘œํ˜„ํ•œ๋‹ค.

REST API์˜ ๊ตฌ์„ฑ

REST API๋Š” ์ž์›(Resource), ํ–‰์œ„(Verb), ํ‘œํ˜„(Representations)์˜ 3๊ฐ€์ง€ ์š”์†Œ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค.

๊ตฌ์„ฑ ์š”์†Œ

๋‚ด์šฉ

ํ‘œํ˜„ ๋ฐฉ๋ฒ•

Resource

์ž์›

HTTP URI

Verb

์ž์›์— ๋Œ€ํ•œ ํ–‰์œ„

HTTP Method

Representations

์ž์›์— ๋Œ€ํ•œ ํ–‰์œ„์˜ ๋‚ด์šฉ

HTTP Message Pay Load

HTTP Method

4๊ฐ€์ง€์˜ Method(GET, POST, PUT, DELETE)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ CRUD๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค.

Method

Action

์—ญํ• 

GET

index/retrieve

๋ชจ๋“ /ํŠน์ • ๋ฆฌ์†Œ์Šค๋ฅผ ์กฐํšŒ

POST

create

๋ฆฌ์†Œ์Šค๋ฅผ ์ƒ์„ฑ

PUT

update

๋ฆฌ์†Œ์Šค๋ฅผ ๊ฐฑ์‹ 

DELETE

delete

๋ฆฌ์†Œ์Šค๋ฅผ ์‚ญ์ œ

REST API ์ค‘์‹ฌ ๊ทœ์น™

URI๋Š” ์ž์›์„ ํ‘œํ˜„ํ•˜๋Š”๋ฐ ์ง‘์ค‘ํ•˜๊ณ , ํ–‰์œ„์— ๋Œ€ํ•œ ์ •์˜๋Š” HTTP Method๋ฅผ ํ†ตํ•ด ํ•˜๋Š” ๊ฒƒ์ด ์„ค๊ณ„์˜ ์ค‘์‹ฌ ๊ทœ์น™์ด๋‹ค.

  • URI๋Š” ์ž์›์„ ํ‘œํ˜„ํ•˜๋Š”๋ฐ ์ง‘์ค‘ : ๋ฆฌ์†Œ์Šค๋ช…์€ ๋™์‚ฌ๋ณด๋‹ค ๋ช…์‚ฌ๋ฅผ ๋งŽ์ด ์‚ฌ์šฉํ•œ๋‹ค.

# ์•ˆ์ข‹์€์˜ˆ
GET /getBooks/1
GET /books/show/1

# ์ข‹์€์˜ˆ
GET /books/1
  • ํ–‰์œ„์— ๋Œ€ํ•œ ์ •์˜๋Š” HTTP Method๋ฅผ ํ†ตํ•ด ํ•œ๋‹ค.

# ์•ˆ์ข‹์€์˜ˆ
GET /books/delete/1

# ์ข‹์€์˜ˆ
DELETE /books/1

์ฐธ๊ณ ๋งํฌ

Last updated