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