0419 - 0425


# 0419 - 0425

# 0420 - REST Resource Naming Guide

  1. A resource can be a singleton or a collection.
    ν•˜λ‚˜μ˜ λ¦¬μ†ŒμŠ€λŠ” μ‹±κΈ€ν„΄ λ˜λŠ” μ»¬λž™μ…˜μ΄ 될 수 μžˆλ‹€.

  2. A resource may contain sub-collection resources also
    λ¦¬μ†ŒμŠ€λŠ” sub-collection λ¦¬μ†ŒμŠ€λ₯Ό 포함할 수 μžˆλ‹€.
    /customers/{Id}/accounts

# REST Resource 넀이밍

Use nouns to represent resources. (λ¦¬μ†ŒμŠ€λ₯Ό ν‘œν•œν•˜κΈ° μœ„ν•΄μ„œ λͺ…사λ₯Ό μ‚¬μš©)
RESTful URIλŠ” λ°˜λ“œμ‹œ λ¦¬μ†ŒμŠ€ κ·Έ 자체λ₯Ό μ–ΈκΈ‰ν•΄μ•Ό ν•˜λ©°, λ¦¬μ†ŒμŠ€μ˜ 행동을 μ–ΈκΈ‰ν•΄μ„œλŠ” μ•ˆλœλ‹€.
예λ₯Ό λ“€λ©΄, μ•„λž˜μ™€ 같은 λ¦¬μ†ŒμŠ€λ“€μ΄ μžˆμ„ λ•Œ URIλŠ” λ‹€μŒκ³Ό 같이 λ””μžμΈ 될 수 μžˆλ‹€.

  • Users of the system
  • User Accounts
  • Network Devices etc
http://api.example.com/device-management/managed-devices 
http://api.example.com/device-management/managed-devices/{device-id} 
http://api.example.com/user-management/users/
http://api.example.com/user-management/users/{id}
  1. document λ¦¬μ†ŒμŠ€ λ¬Έμ„œμ˜ μœ ν˜•μ„ λ‚˜νƒ€λ‚  λ•ŒλŠ” 'λ‹¨μˆ˜'λ₯Ό μ‚¬μš©.
http://api.example.com/device-management/managed-devices/{device-id}
http://api.example.com/user-management/users/{id}
http://api.example.com/user-management/users/admin
  1. collection λ¦¬μ†ŒμŠ€ Collection λ‹¨μœ„μ˜ λ¦¬μ†ŒμŠ€λ₯Ό ν‘œμ‹œν•  λ•ŒλŠ” '볡수'λ₯Ό μ‚¬μš©
http://api.example.com/device-management/managed-devices
http://api.example.com/user-management/users
http://api.example.com/user-management/users/{id}/accounts
  1. store λ¦¬μ†ŒμŠ€ μ €μž₯에 κ΄€ν•œ μš”μ²­μ€ ν΄λΌμ΄μ–ΈνŠΈκ°€ κ΄€λ¦¬ν•˜λŠ” λ¦¬μ†ŒμŠ€ μ €μž₯μ†Œμ΄λ‹€. λ”°λΌμ„œ '볡수'λ₯Ό μ‚¬μš©ν•œλ‹€
http://api.example.com/song-management/users/{id}/playlists
  1. controller λ¦¬μ†ŒμŠ€ 컨트둀러 λ¦¬μ†ŒμŠ€λŠ” μ‹€ν–‰ κ°€λŠ₯ν•œ κΈ°λŠ₯κ³Ό ν•¨κ»˜ νŒŒλΌλ―Έν„° ν˜Ήμ€ 리턴 κ°’μœΌλ‘œ 이름 μ§“λŠ”λ‹€.
    이 λ•ŒλŠ” '동사'λ₯Ό μ‚¬μš©ν•œλ‹€.
http://api.example.com/cart-management/users/{id}/cart/checkout
http://api.example.com/song-management/users/{id}/playlist/play

# URI의 일관성

  1. 계측 ꡬ쑰λ₯Ό ν‘œν˜„ν•˜κΈ° μœ„ν•΄μ„œ '/'λ₯Ό μ‚¬μš©ν•œλ‹€.
http://api.example.com/device-management
http://api.example.com/device-management/managed-devices
http://api.example.com/device-management/managed-devices/{id}
http://api.example.com/device-management/managed-devices/{id}/scripts
http://api.example.com/device-management/managed-devices/{id}/scripts/{id}
  1. 끝에 '/'κ°€ 뢙지 μ•Šλ„λ‘ ν•œλ‹€.

  2. 언더바 μ‚¬μš©μ€ ν”Όν•˜λ©° '-'을 μ‚¬μš©ν•œλ‹€.

  3. νŽΈλ¦¬ν•¨ + μ»¨λ²€μ…˜μ„ μ‹œν‚€μ§€ μœ„ν•΄μ„œ μ†Œλ¬Έμžλ₯Ό μ‚¬μš©ν•œλ‹€.

  4. 파일 ν™•μž₯자λ₯Ό 포함 ν•˜μ§€ μ•ŠλŠ”λ‹€.

  5. URIλ₯Ό μ‚¬μš©ν•΄μ„œ CRUD κΈ°λŠ₯의 μˆ˜ν–‰λ˜μ—ˆμŒμ„ ν‘œμ‹œν•΄μ„œλŠ” μ•ˆλœλ‹€.
    URIλŠ” μžμ›μ— λŒ€γ…‘ν•œ μ–΄λ– ν•œ 행동을 λ‚˜νƒ€λ‚΄λ©΄ μ•ˆλ˜κ³ , μžμ›μ„ λ…λ¦½μ μœΌλ‘œ μ‹λ³„ν•˜λŠ” λ°©μ‹μœΌλ‘œ μ‚¬μš©λ˜μ–΄μ•Ό ν•œλ‹€. μ–΄λ–€ κΈ°λŠ₯이 μˆ˜ν–‰λ˜λŠ”μ§€ ν‘œμ‹œν•˜κΈ° μœ„ν•΄μ„œλŠ” HTTP μš”μ²­ 방법을 μ‚¬μš©ν•œλ‹€.

HTTP GET http://api.example.com/device-management/managed-devices  //Get all devices
HTTP POST http://api.example.com/device-management/managed-devices  //Create new Device

HTTP GET http://api.example.com/device-management/managed-devices/{id}  //Get device for given Id
HTTP PUT http://api.example.com/device-management/managed-devices/{id}  //Update device for given Id
HTTP DELETE http://api.example.com/device-management/managed-devices/{id}  //Delete device for given Id
  1. μΏΌλ¦¬μŠ€νŠΈλ§μ„ μ΄μš©ν•˜λŠ” 것을 고렀해라
    νŠΉμ • λ¦¬μ†ŒμŠ€μ˜ 속성을 κΈ°μ€€μœΌλ‘œ μ •λ ¬, 필터링을 μžμ£Όν•˜κ²Œ 될 수 μžˆλ‹€. 이λ₯Ό μœ„ν•΄μ„œ μƒˆλ‘œμš΄ APIλ₯Ό λ§Œλ“€κΈ°λ³΄λ‹¨, μž…λ ₯ λ§€κ°œλ³€μˆ˜λ₯Ό μΏΌλ¦¬μŠ€νŠΈλ§μ— μ „λ‹¬ν•˜λ„λ‘ ν•œλ‹€.
Last update: September 13, 2022 21:44
Contributors: ahnjs , jaesungahn91