λ°˜μ‘ν˜•
REST (Representational State Transfer)
μ„€λͺ…

μžμ›μ„ ν‘œν˜„(Representational)으둜 κ΅¬λΆ„ν•˜μ—¬ ν•΄λ‹Ή μžμ›μ˜ μƒνƒœ(State)λ₯Ό μ£Όκ³  λ°›λŠ”(Transfer)λ‹€.
HTTP URI(Uniform Resource Identifier)을 톡해 μžμ›(Resource)을 λͺ…μ‹œν•˜κ³ , Http Method(GET, POST, PUT, DELETE)을 톡해 μžμ›μ— λŒ€ν•œ CRUD Operation을 적용

✱ URI (Uniform Resource Identifier)
인터넷 μžμ›μ„ λ‚˜νƒ€λ‚΄λŠ” μœ μΌν•œ μ£Όμ†Œ
scheme:[//[user[:password]@]host[:port]][/path][?query][#fragment]
 - URN: μžμ›μ˜ 이름 (μ‹λ³„μž)
 - URL: μžμ›μ˜ μœ„μΉ˜ 

 

κ΅¬μ„±μš”μ†Œ

1. μžμ› (Resource)
β€£ Http URI (ex. /users/:userId)

2. ν–‰μœ„ (Method)
β€£ GET, POST, PUT, DELETE,
β€£ HEAD (μš”μ²­ header μ •λ³΄λ§Œ 응닡),
β€£ PATCH (PUTκ³Ό λ‹€λ₯΄κ³ , μžμ›μ˜ μΌλΆ€λ§Œ μˆ˜μ •ν•˜κ³ μž ν• λ•Œ μ‚¬μš©),
β€£ OPTION (ν˜„μž¬ End-pointκ°€ 제곡 κ°€λŠ₯ν•œ API methodλ₯Ό 응닡)

3. ν‘œν˜„ (Representation of Resource)
  Client(λΈŒλΌμš°μ €)κ°€ μžμ›μ˜ μƒνƒœμ— λŒ€ν•œ μ‘°μž‘μ„ μš”μ²­(Request)ν•˜λ©΄ μ„œλ²„λŠ” 이에 μ μ ˆν•œ 응닡(Response)을 보낸닀.
  JSON, XML, TEXT, RSS λ“± μ—¬λŸ¬ ν˜•νƒœλ‘œ ν‘œν˜„

 

REST API νŠΉμ§•

1. ν΄λΌμ΄μ–ΈνŠΈ/μ„œλ²„
β€£ μ•„ν‚€ν…μ²˜λ₯Ό λ‹¨μˆœν™” μ‹œν‚€κ³  μž‘μ€λ‹¨μœ„λ‘œ λΆ„λ¦¬ν•¨μœΌλ‘œμ¨
ν΄λΌμ΄μ–ΈνŠΈ - μ„œλ²„ 각 νŒŒνŠΈκ°€ λ…λ¦½μ μœΌλ‘œ κ°œμ„ λ  수 μžˆλ„λ‘ ν•œλ‹€. 


2. μƒνƒœμ—†μŒ
β€£ ν΄λΌμ΄μ–ΈνŠΈμ˜ μƒνƒœκ°€ μ„œλ²„μ— μ €μž₯λ˜μ–΄μ„œλŠ” μ•ˆλœλ‹€.

3. λ ˆμ΄μ–΄λ“œ μ•„ν‚€ν…μ²˜ (Layered Architecture)
β€£ ν΄λΌμ΄μ–ΈνŠΈ - μ„œλ²„ μ—°κ²° μ‚¬μ΄μ˜ 쀑간 μ„œλ²„κ°€ μ‘΄μž¬ν•˜λŠ” 경우 (ν΄λΌμ΄μ–ΈνŠΈ - μ€‘κ°„μ„œλ²„ - μ„œλ²„),
μ€‘κ°„μ„œλ²„(κ²Œμ΄νŠΈμ›¨μ΄, λ°©ν™”λ²½, ν”„λ‘μ‹œ etc)λŠ” λ‘œλ“œλ°ΈλŸ°μ‹± ν˜Ήμ€ 곡유 μΊμ‹œ κΈ°λŠ₯을 μ œκ³΅ν•¨μœΌλ‘œμ¨
μ‹œμŠ€ν…œ 규λͺ¨ ν™•μž₯성을 ν–₯μƒμ‹œν‚€λŠ”λ° 유용

4. μΊμ‹œ (Cache)
β€£ ν΄λΌμ΄μ–ΈνŠΈ 응닡을 캐싱할 수 μžˆμ–΄μ•Ό 함. μΊμ‹±ν•¨μœΌλ‘œμ„œ μ„œλ²„μ— λΆ€ν•˜ μ΅œμ†Œν™”

5. μ½”λ“œ 온 λ””λ§¨λ“œ(Code on demand)
β€£ μš”청이 였면 μ½”λ“œλ₯Ό μ€€λ‹€λŠ” 의미둜 νŠΉμ • μ‹œμ μ— μ„œλ²„κ°€ νŠΉμ • κΈ°λŠ₯을 μˆ˜ν–‰ν•˜λŠ” 슀크립트 λ˜λŠ”
ν”ŒλŸ¬κ·ΈμΈμ„
ν΄λΌμ΄μ–ΈνŠΈμ— μ „λ‹¬ν•΄μ„œ ν•΄λ‹Ή κΈ°λŠ₯을 λ™μž‘ν•˜λ„λ‘ ν•˜λŠ”κ²ƒ. (μžλ°”μŠ€ν¬λ¦½νŠΈ, ν”Œλž˜μ‹œ etc)

6. 톡합 μΈν„°νŽ˜μ΄μŠ€
β€£ μΌκ΄€μ μΈ μΈν„°νŽ˜μ΄μŠ€λ‘œ 뢄리 λ˜μ–΄μ•Ό 함.

 

REST μΈν„°νŽ˜μ΄μŠ€ κ·œμΉ™

1. λ¦¬μ†ŒμŠ€ 식별
β€£ μš”μ²­ 내에 기술된 κ°œλ³„ μžμ›μ„ 식별할 수 μžˆμ–΄μ•Ό ν•œλ‹€. (URI)

2. ν‘œν˜„μ„ ν†΅ν•œ λ¦¬μ†ŒμŠ€ 처리
β€£ λ‹€μ–‘ν•œ μ½˜ν…μΈ  μœ ν˜•μœΌλ‘œ ν‘œν˜„ κ°€λŠ₯ (JSON, XML, HTML ..)

3. 자기 λ¬˜μ‚¬ 메세지
β€£ Http header 에 메타 데이터 정보λ₯Ό μΆ”κ°€ν•΄μ„œ μ‹€μ œ λ°μ΄ν„°μ™€λŠ” κ΄€λ ¨ μ—†μ§€λ§Œ
데이터에 λŒ€ν•œ μ„€λͺ…을 λ‚˜νƒ€λ‚΄λŠ” 정보λ₯Ό 담을 수 있음.

4. μ–΄ν”Œλ¦¬μΌ€μ΄μ…˜μ˜ μƒνƒœμ— λŒ€ν•œ ν•˜μ΄νΌλ―Έλ””μ–΄(HATEOAS, Hypermedia As The Engine Of Application State)
β€£ REST API κ°œλ°œν•  λ•Œμ— λ‹¨μˆœ λ°μ΄ν„°λ§Œ μ „λ‹¬ν•˜μ§€ μ•Šκ³ , 링크 μ •λ³΄κΉŒμ§€ ν¬ν•¨ν•˜μ—¬ 전달 (ν•˜μ΄νΌ ν…μŠ€νŠΈ 링크)
β€£ λ¦¬μ†ŒμŠ€ μƒνƒœκ°€ μ „μ΄λ˜λŠ” κ²½μš°μ— λ³€κ²½λ˜λŠ” 정보λ₯Ό μ œκ³΅ν•˜κ³ μž 함.
(등둝 μš”μ²­ ν›„, λ³€κ²½ 된 정보λ₯Ό μ’€ 더 μžμ„Ένžˆ μ•Œκ³ μž ν• λ•Œ ν•˜μ΄νΌ 링크도 같이 제곡)
    

 

REST API 
μ„€λͺ…

REST μ•„ν‚€ν…μ²˜μ˜ μ œμ•½ 쑰건을 μ€€μˆ˜ν•˜λŠ” μ• ν”Œλ¦¬μΌ€μ΄μ…˜ ν”„λ‘œκ·Έλž˜λ° μΈν„°νŽ˜μ΄μŠ€

 

RESTful의 λͺ©μ 

API μ΄μš©μžκ°€ ν•΄λ‹Ή API 으둜 데이터λ₯Ό μ–»κ³ , νŠΉμ • κΈ°λŠ₯을 νŒŒμ•…ν•  수 μžˆλ„λ‘ ν•˜λŠ” 것

 

λ¦¬μ†ŒμŠ€ μ›ν˜•

λ„νλ¨ΌνŠΈ (document)
β€£ κ°μ²΄ μΈμŠ€ν„΄μŠ€λ‚˜ λ°μ΄ν„°λ² μ΄μŠ€ λ ˆμ½”λ“œμ™€ μœ μ‚¬ν•œ κ°œλ…

μ»¬λ ‰μ…˜ (collection)
β€£ μ„œλ²„μ—μ„œ κ΄€λ¦¬ν•˜λŠ” 디렉터리 λ¦¬μ†ŒμŠ€ 

μŠ€ν† μ–΄ (store)
β€£ ν΄λΌμ΄μ–ΈνŠΈμ—μ„œ κ΄€λ¦¬ν•˜λŠ” λ¦¬μ†ŒμŠ€ μ €μž₯μ†Œ
β€£ API ν΄λΌμ΄μ–ΈνŠΈκ°€ λ¦¬μ†ŒμŠ€λ₯Ό 등둝/μˆ˜μ •/μ‚­μ œμ— κ΄€μ—¬

컨트둀러 (controller)
β€£ μ ˆμ°¨μ μΈ κ°œλ…μ„ λͺ¨λΈν™” ν•œ 것

 

✰ REST API λ””μžμΈμ„ μœ„ν•œ κ·œμΉ™

좔상적인 것 보단, ꡬ체적인 것이 μ’‹λ‹€.
ex) /animals -> /pigs

동사λ₯Ό μ‚¬μš©ν•˜μ§€ μ•ŠλŠ”λ‹€. (λͺ…사λ₯Ό μ‚¬μš©)
method λ₯Ό 동사 λŒ€μš©μœΌλ‘œ μ‚¬μš©.

λ‹¨μˆ˜λ³΄λ‹¨, 볡수λ₯Ό μ‚¬μš©ν•˜λŠ” 것을 ꢌμž₯ν•œλ‹€.
ex) /thing  ->  /things or /things/{id}

μŠ¬λž˜μ‹œ(/) 을 μ‚¬μš©ν•˜μ—¬ 계측관계λ₯Ό ν‘œμ‹œν•΄μ•Ό ν•œλ‹€.
λ¦¬μ†ŒμŠ€κ°„ μ—°κ΄€κ΄€κ³„λŠ” /λ¦¬μ†ŒμŠ€λͺ…/λ¦¬μ†ŒμŠ€ID/관계가 μžˆλŠ” λ‹€λ₯Έ λ¦¬μ†ŒμŠ€λͺ… 으둜 ν‘œν˜„ν•œλ‹€.

ex) GET /users/{userid}/devices (μ†Œμœ μžκ°€ κ°€μ§€κ³ μžˆλŠ” λ””λ°”μ΄μŠ€ λͺ©λ‘?)

URL λ§ˆμ§€λ§‰μ— μŠ¬λž˜μ‹œ(/) 을 ν¬ν•¨ν•˜μ§€ μ•ŠλŠ”λ‹€.
μŠ¬λž˜μ‹œλ₯Ό ν¬ν•¨ν•œλ‹€λ©΄, μŠ¬λž˜μ‹œ λ‹€μŒμ— μ‹λ³„μžκ°€ μ™€μ•Όν•˜λŠ”λ° μ˜€μ§€ μ•ŠμŒμœΌλ‘œ ν˜Όλ™μ„ 쀄 여지가 있음.

URI의 가독성을 λ†’νžˆλ €λ©΄ ν•˜μ΄ν”ˆ(-)을 μ‚¬μš©ν•΄μ•Ό ν•œλ‹€.

URI에 밑쀄(_)을 μ‚¬μš©ν•΄μ„  μ•ˆλœλ‹€.
보기가 어렀움. 가독성

URI κ²½λ‘œμ—λŠ” μ†Œλ¬Έμžλ₯Ό μ‚¬μš©ν•΄μ•Ό ν•œλ‹€.

파일 ν™•μž₯μžλŠ” μ‚¬μš©ν•˜μ§€ μ•ŠλŠ”λ‹€.

 


μ°Έκ³ 

https://www.redhat.com/ko/topics/api/what-is-a-rest-api

(μ±…) μŠ€ν”„λ§ λΆ€νŠΈλ‘œ λ°°μš°λŠ” μžλ°” μ›Ή 개발

 

REST API(RESTful API, λ ˆμŠ€νŠΈν’€ API)λž€ - μ„œλ²„, κ΅¬ν˜„, μ‚¬μš©λ²•

REST API(RESTful API)λž€ REST μ•„ν‚€ν…μ²˜μ˜ μ œμ•½ 쑰건을 μ€€μˆ˜ν•˜λŠ” μ• ν”Œλ¦¬μΌ€μ΄μ…˜ ν”„λ‘œκ·Έλž˜λ° μΈν„°νŽ˜μ΄μŠ€λ₯Ό λœ»ν•©λ‹ˆλ‹€. api μ„œλ²„, rest api κ΅¬ν˜„ 및 μ‚¬μš©λ²•μ„ μ„€λͺ…ν•©λ‹ˆλ‹€.

www.redhat.com

https://nsinc.tistory.com/192

 

URL vs URI vs URN

인터넷을 μ‚¬μš©ν•˜λ©΄μ„œ 많이 λ§Œλ‚˜κ²Œ λ˜λŠ” URI, URL, URN의 κ°œλ…μ— λŒ€ν•΄μ„œ μ •λ¦¬ν•΄λ³΄κ³ μž ν•©λ‹ˆλ‹€. URI, URL, URN은 기술적인 ꡬ뢄이 μ•„λ‹Œ κ°œλ…μ μΈ 차이라고 λ³Ό 수 μžˆμœΌλ―€λ‘œ μ°Έκ³  λ°”λžλ‹ˆλ‹€. URI vs URL vs URN ?

nsinc.tistory.com

https://spoqa.github.io/2013/06/11/more-restful-interface.html

 

RESTful APIλ₯Ό μ„€κ³„ν•˜κΈ° μœ„ν•œ λ””μžμΈ 팁

RESTful apiλ₯Ό μ„€κ³„ν•˜κΈ° μœ„ν•œ κ°œλ…λ“€μ„ μΆ”κ°€μ μœΌλ‘œ μ•Œμ•„λ³΄κ³  μœ μš©ν•˜κ²Œ μ“°μΌλ§Œν•œ HTTP헀더와 μƒνƒœμ½”λ“œλ₯Ό μ‚΄νŽ΄λ΄…λ‹ˆλ‹€.

spoqa.github.io

https://dzone.com/articles/7-rules-for-rest-api-uri-design-1

 

7 Rules for REST API URI Design - DZone Integration

URIs, or Uniform Resource Identifiers, should be designed to be readable and clearly communicate the API resource model. These rules will help you succeed.

dzone.com

https://gmlwjd9405.github.io/2018/09/21/rest-and-restful.html

 

[Network] RESTλž€? REST APIλž€? RESTfulμ΄λž€? - Heee's Development Blog

Step by step goes a long way.

gmlwjd9405.github.io

https://www.slideshare.net/nexusz99/rest-api-48600643

 

REST API λ””μžμΈ κ°œμš”

REST APIκ°€ 무엇이고 그것을 μ–΄λ–»κ²Œ λ””μžμΈν•΄μ•Όν•˜λŠ”μ§€μ— λŒ€ν•΄ λ‚˜λ¦„λŒ€λ‘œ 정리λ₯Ό ν•΄λ³΄μ•˜μŠ΅λ‹ˆλ‹€.

www.slideshare.net

https://zsgg.tistory.com/entry/REST-API-%EB%94%94%EC%9E%90%EC%9D%B8-%EA%B7%9C%EC%B9%99

 

REST API λ””μžμΈ κ·œμΉ™

μ—¬μ „νžˆ μš°λ¦¬λŠ” λ‹€μŒκ³Ό 같은 μ§ˆλ¬Έλ“€μ— λŒ€ν•œ 닡을 μ°Ύμ•„μ•Ό ν•œλ‹€. URI 경둜path μ„Έκ·Έλ¨ΌνŠΈλŠ” μ–Έμ œ 볡수둜 써야 ν•˜λŠ”κ°€? λ¦¬μ†ŒμŠ€μ˜ μƒνƒœλ₯Ό μ—…λ°μ΄νŠΈν•˜λ €λ©΄, μ–΄λ–€ λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•΄μ•Ό ν•˜λŠ”κ°€? CRUD12κ°€ μ•„λ‹Œ

zsgg.tistory.com

https://sanghaklee.tistory.com/57

 

RESTful API 섀계 κ°€μ΄λ“œ

1. RESTful API 섀계 κ°€μ΄λ“œ λ³Έ λ¬Έμ„œλŠ” REST APIλ₯Ό μ’€ 더 RESTful ν•˜κ²Œ μ„€κ³„ν•˜λ„λ‘ κ°€μ΄λ“œν•  λͺ©μ μœΌλ‘œ λ§Œλ“€μ–΄μ‘Œλ‹€. λ”°λΌμ„œ, 기본적인 REST API κ°œλ… μ„€λͺ…은 μ•„λž˜μ˜ 링크둜 λŒ€μ‹ ν•œλ‹€. REST API μ œλŒ€λ‘œ μ•Œκ³  μ‚¬μš©

sanghaklee.tistory.com

https://meetup.toast.com/posts/92

 

REST API μ œλŒ€λ‘œ μ•Œκ³  μ‚¬μš©ν•˜κΈ° : NHN Cloud Meetup

REST API μ œλŒ€λ‘œ μ•Œκ³  μ‚¬μš©ν•˜κΈ°

meetup.toast.com

 

λ°˜μ‘ν˜•

'개발 > etc' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

SSE (Server Sent Event)  (1) 2023.08.20
Vault  (1) 2023.02.07
ν—₯사고날 μ•„ν‚€ν…μ²˜ (Hexagonal Architecture)  (2) 2022.09.25
JWT (JSON WEB TOKEN)  (0) 2021.12.22
HTTPκ΄€λ ¨ (https, spdy, ajax, websocket)  (0) 2018.12.09

+ Recent posts