๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐ŸŒฟ Spring/โœ… RESTful Web Service

6. RESTful API ์„ค๊ณ„ ๊ฐ€์ด๋“œ

by nitronium102 2023. 6. 20.

Richardson Maturity Model

A way to grade your API according to the constraints of REST

Level 0

expose soap web services in rest style

Level 1

expose resources with proper url

note : improper use of http methods → ๋ชจ๋“  ์š”์ฒญ์„ GET, POST๋กœ ๋ฐ›๊ฑฐ๋‚˜ ์—๋Ÿฌ/200์œผ๋กœ๋งŒ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ˜•ํƒœ

Level 2

level1 + HTTP methods(GET, POST, PUT, DELETE ๊ตฌ๋ถ„)

Level 3

level2 + HATEOAS

DATA + NEXT POSSIBLE ACTIONS ⇒ ์ตœ์†Œํ•œ์˜ end point๋งŒ์„ ๊ฐ€์ง€๊ณ  ๋‹ค์Œ url์„ ์•Œ ์ˆ˜ ์žˆ๊ฒŒ ํ•จ

์„ค๊ณ„ ์‹œ ๊ณ ๋ ค ์‚ฌํ•ญ

  1. consumer first : ๊ฐœ๋ฐœ์ž ์ค‘์‹ฌ์˜ ์„ค๊ณ„ ๋ณด๋‹ค๋Š” ์†Œ๋น„์ž ์ž…์žฅ์—์„œ ๊ฐ„๋‹จ๋ช…๋ฃŒํ•˜๊ณ  ์ง๊ด€์ ์ธ API ์„ค๊ณ„
  2. make best use of HTTP : HTTP ์žฅ์  ์‚ด๋ฆฌ๊ธฐ
  3. Request methods
  • GET
  • POST
  • PUT
  • DELETE
  1. Response Status
  • 200
  • 404
  • 400
  • 201
  • 401
  1. No secure info in URI
  2. use plurals

prefer users to user

  1. use nouns for resources
  2. for exceptions

define a consistent approach

url์€ ๋‹จ์ˆœํ•˜๊ฒŒ, parameter/header/HTTP ์ƒํƒœ์ฝ”๋“œ๋ฅผ ๋‹ค์–‘ํ•˜๊ฒŒ

PUT /gists/{id}/star

DELETE /gists/{id}/star

๋Œ“๊ธ€