REST API, ์•Œ๊ณ  ์‚ฌ์šฉํ•˜์ž!
Web/Server

REST API, ์•Œ๊ณ  ์‚ฌ์šฉํ•˜์ž!

 

๐Ÿ“˜ REST API์˜ ์ •์˜

 ์šฐ์„ , REST๊ฐ€ ์–ด๋–ค ๊ฒƒ์„ ์˜๋ฏธํ•˜๋Š”์ง€ ์•Œ๊ณ  ๊ฐ€๋„๋ก ํ•˜์ž.

 REST๋Š” Representational State Transfer์˜ ์•ฝ์ž์ด๋ฉฐ, ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ตฌ์„ฑ๋˜์–ด์žˆ๋‹ค.

  • ์ž์› (Resource) : URI
  • ํ–‰์œ„ (Verb) : HTTP Method
  • ํ‘œํ˜„ (Representations)

->  ๋”ฐ๋ผ์„œ REST API๋Š” URI๋ฅผ ํ†ตํ•ด์„œ ์ž์›์„ ๋‚˜ํƒ€๋‚ด๊ณ , HTTP Method๋ฅผ ์ด์šฉํ•ด ํ•ด๋‹น ์ž์›์˜ ํ–‰์œ„๋ฅผ ๊ทœ์ •ํ•˜์—ฌ ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ›๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค.

 

 

๐Ÿ’กREST์˜ ํŠน์ง•

  • Uniform Interface
    • URI๋กœ ์ง€์ •ํ•œ ๋ฆฌ์†Œ์Šค์— ๋Œ€ํ•œ ์กฐ์ž‘์„ ํ†ต์ผ๋˜๊ณ  ํ•œ์ •์ ์ธ ์ธํ„ฐํŽ˜์ด์Šค๋กœ ์ˆ˜ํ–‰ํ•˜๋Š” ์Šคํƒ€์ผ์„ ๋งํ•œ๋‹ค.
  • Stateless
    • REST๋Š” ๋ฌด์ƒํƒœ์„ฑ ์„ฑ๊ฒฉ์„ ๊ฐ–๊ณ , ์ž‘์—…์„ ์œ„ํ•œ ์ƒํƒœ์ •๋ณด๋ฅผ ๋”ฐ๋กœ ์ €์žฅํ•˜๊ฑฐ๋‚˜ ๊ด€๋ฆฌํ•˜์ง€ ์•Š๋Š”๋‹ค. ์„ธ์…˜ ์ •๋ณด๋‚˜ ์ฟ ํ‚ค์ •๋ณด๋ฅผ ๋ณ„๋„๋กœ ์ €์žฅํ•˜๊ณ  ๊ด€๋ฆฌํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— API ์„œ๋ฒ„๋Š” ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ๋งŒ์„ ๋‹จ์ˆœํžˆ ์ฒ˜๋ฆฌํ•˜๋ฉด ๋œ๋‹ค.
    • ์ด๋ฅผ ํ†ตํ•ด์„œ ์„œ๋น„์Šค์˜ ์ž์œ ๋„๊ฐ€ ๋†’์•„์ง€๊ณ  ์„œ๋ฒ„์—์„œ ๋ถˆํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ๊ด€๋ฆฌํ•˜์ง€ ์•Š๋Š”๋‹ค.
  • Cacheable
    • ๊ธฐ์กด ์›น ํ‘œ์ค€์„ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— HTTP๊ฐ€ ๊ฐ€์ง„ ์บ์‹ฑ ๊ธฐ๋Šฅ์„ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
  • Self-descriptiveness
    • REST API ๋ฉ”์„ธ์ง€๋งŒ ๋ณด๊ณ ๋„ ์ด๋ฅผ ์‰ฝ๊ฒŒ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋Š” ์ž์ฒด ํ‘œํ˜„ ๊ตฌ์กฐ๋กœ ๋˜์–ด์žˆ๋‹ค.
  • Client-Server ๊ตฌ์กฐ
    • REST ์„œ๋ฒ„๋Š” API๋ฅผ ์ œ๊ณตํ•˜๊ณ , ํด๋ผ์ด์–ธํŠธ๋Š” ์‚ฌ์šฉ์ž ์ธ์ฆ์ด๋‚˜ ์ปจํ…์ŠคํŠธ ๋“ฑ์„ ์ง์ ‘ ๊ด€๋ฆฌํ•˜๋Š” ๊ตฌ์กฐ๋กœ ๊ฐ๊ฐ์˜ ์—ญํ• ์ด ํ™•์‹คํžˆ ๊ตฌ๋ถ„๋˜๊ธฐ ๋•Œ๋ฌธ์— ํด๋ผ์ด์–ธํŠธ์™€ ์„œ๋ฒ„์—์„œ ๊ฐœ๋ฐœํ•ด์•ผ ํ•  ๋‚ด์šฉ์ด ๋ช…ํ™•ํ•ด์ง€๊ณ  ์„œ๋กœ๊ฐ„์˜ ์˜์กด์„ฑ์ด ์ค„์–ด๋“ค๊ฒŒ ๋œ๋‹ค.
  • ๊ณ„์ธตํ˜• ๊ตฌ์กฐ
    • REST ์„œ๋ฒ„๋Š” ๋‹ค์ค‘ ๊ณ„์ธต์œผ๋กœ ๊ตฌ์„ฑ๋  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ, ์•”ํ˜ธํ™” ๊ณ„์ธต ๋“ฑ์„ ์ถ”๊ฐ€ํ•ด ๊ตฌ์กฐ์ƒ์˜ ์œ ์—ฐ์„ฑ๊ณผ ํ”„๋ก์‹œ, ๊ฒŒ์ดํŠธ์›จ์ด ๊ฐ™์€ ๋„คํŠธ์›Œํฌ ๊ธฐ๋ฐ˜์˜ ์ค‘๊ฐ„๋งค์ฒด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•œ๋‹ค.

 

๐Ÿ—๏ธ RESTFUL URI์„ค๊ณ„ ์›์น™

 RESTFULํ•œ URI๋ฅผ ์„ค๊ณ„ํ• ๋•Œ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๋‘๊ฐ€์ง€ ์ค‘์‹ฌ ์›์น™์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

   1๏ธโƒฃ URI๋Š” ์ •๋ณด์˜ ์ž์›์„ ํ‘œํ˜„ํ•ด์•ผ ํ•œ๋‹ค.

   2๏ธโƒฃ ์ž์›์— ๋Œ€ํ•œ ํ–‰์œ„๋Š” HTTP METHOD๋กœ ํ‘œํ˜„ํ•ด์•ผ ํ•œ๋‹ค.

-> ์ฆ‰, ์—ฌ๊ธฐ์„œ ์ค‘์š”ํ•œ ํ‚ค์›Œ๋“œ๋Š” "์ž์›(Resource)", "ํ–‰์œ„(Verb)-HTTP Method" ์ž„์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. ํ•ด๋‹น ํ‚ค์›Œ๋“œ์— ๋Œ€ํ•ด์„œ ์ œ๋Œ€๋กœ ์•Œ๊ณ  ๊ฐ€๋„๋ก ํ•˜์ž!

 

๐Ÿ“„Resource์˜ ์ข…๋ฅ˜

 ์ž์›์˜ ์ข…๋ฅ˜๋Š” ์ด ๋„ค๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค.

 1) ๋ฌธ์„œ(Document)

  • ๋‹จ์ผ ๊ฐœ๋…(ํŒŒ์ผ ํ•˜๋‚˜, ๊ฐ์ฒด ์ธ์Šคํ„ด์Šค, ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค row)
  • ๋‹จ์ˆ˜ ์‚ฌ์šฉ (/device-management, /user-management)

2) ์ปฌ๋ ‰์…˜(Collection)

  • ์„œ๋ฒ„๊ฐ€ ๊ด€๋ฆฌํ•˜๋Š” ๋ฆฌ์†Œ์Šค ๋””๋ ‰ํ† ๋ฆฌ๋กœ, ์„œ๋ฒ„๊ฐ€ ๋ฆฌ์†Œ์Šค์˜ URI๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๊ด€๋ฆฌ
  • ๋ณต์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ผ
  • POST ๊ธฐ๋ฐ˜ ๋“ฑ๋ก
  • ์˜ˆ) /users, /accounts....

3) ์Šคํ† ์–ด(Store)

  • ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๊ด€๋ฆฌํ•˜๋Š” ์ž์› ์ €์žฅ์†Œ๋กœ, ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋ฆฌ์†Œ์Šค์˜ URI๋ฅผ ์•Œ๊ณ  ๊ด€๋ฆฌ
  • PUT ๊ธฐ๋ฐ˜ ๋“ฑ๋ก
  • ์˜ˆ) ์ •์  ์ปจํ…์ธ  ๊ด€๋ฆฌ, ์›๊ฒฉ ํŒŒ์ผ ๊ด€๋ฆฌ
  • ๋ณต์ˆ˜ ์‚ฌ์šฉ (/files)

4) ์ปจํŠธ๋กค URI ํ˜น์€ ์ปจํŠธ๋กค๋Ÿฌ(Controller)

  • ๋ฌธ์„œ, ์ปฌ๋ ‰์…˜, ์Šคํ† ์–ด๋กœ ํ•ด๊ฒฐํ•˜๊ธฐ ์–ด๋ ค์šด ์ถ”๊ฐ€ ํ”„๋กœ์„ธ์Šค ์‹คํ–‰
  • ๋™์‚ฌ๋ฅผ ์ง์ ‘ ์‚ฌ์šฉ
  • ์˜ˆ) GET, POST๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” HTTP FORM์˜ ๊ฒฝ์šฐ ์ปจํŠธ๋กค URI(๋™์‚ฌ๋กœ ๋œ ๋ฆฌ์†Œ์Šค ๊ฒฝ๋กœ)๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ex) /members/delete, /members/new ๋“ฑ
  • ๋™์‚ฌ ์‚ฌ์šฉ (/checkout, /play ๋“ฑ)
  • ์ฆ‰, ์ž์›์ด control ์ž์›์ธ ๊ฒฝ์šฐ์—๋งŒ ์˜ˆ์™ธ์ ์œผ๋กœ ๋™์‚ฌ ์‚ฌ์šฉ์„ ํ—ˆ์šฉํ•˜๋Š” ๊ฒƒ์ด๋‹ค. 

 

๐Ÿ“„HTTP Method์˜ ์ข…๋ฅ˜

- ํ–‰์œ„๋ฅผ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ์ฃผ๋กœ ์‚ฌ์šฉํ•˜๋Š” HTTP method๋Š” ์œ„์˜ ๋‹ค์„ฏ๊ฐœ์™€ ๊ฐ™๋‹ค.

- ์—ฌ๊ธฐ์„œ HTTP ๋ฉ”์†Œ๋“œ๋ฅผ ์ •ํ™•ํžˆ ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋ฉฑ๋“ฑ์„ฑ์ด๋ผ๋Š” ํ‚ค์›Œ๋“œ์˜ ๊ฐœ๋…์„ ์•Œ๊ณ  ๊ฐ€์•ผ ํ•œ๋‹ค.

 

๐Ÿ’ก ๋ฉฑ๋“ฑ์„ฑ(Idempotence)์ด๋ž€?

๋ฉฑ๋“ฑ์„ฑ์ด๋ž€ ์—ฌ๋Ÿฌ๋ฒˆ ์ˆ˜ํ–‰ํ•ด๋„ ๊ทธ ๊ฒฐ๊ณผ๊ฐ€ ๊ฐ™์Œ์„ ์˜๋ฏธํ•œ๋‹ค. 

์„œ๋ฒ„์˜ ์ƒํƒœ๋Š” ๋ฉฑ๋“ฑ์„ฑ์ด ์œ ์ง€๋˜์–ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ ๊ฐ™์€ ํ–‰์œ„๋ฅผ ์—ฌ๋Ÿฌ๋ฒˆ ๋ฐ˜๋ณตํ•˜๋”๋ผ๋„ ๊ฐ™์€ ํšจ๊ณผ๋ฅผ ๊ฐ€์ ธ์•ผ ํ•œ๋‹ค.

์„œ๋ฒ„์—์„œ ์‘๋‹ต์ด ๋‹ค๋ฅผ ์ˆ˜๋Š” ์žˆ์ง€๋งŒ, ์š”์ฒญ์ด ์˜๋„ํ•œ ํšจ๊ณผ๋ฅผ ๋ฐœํœ˜ํ• ๋•Œ ๋ฉฑ๋“ฑ์„ฑ์ด ์œ ์ง€๋จ์„ ์˜๋ฏธํ•œ๋‹ค.

  • HTTP ๋ฉ”์†Œ๋“œ์—์„œ์˜ ๋ฉฑ๋“ฑ์„ฑ 
4.2.2.  Idempotent Methods

   A request method is considered "idempotent" if the intended effect on
   the server of multiple identical requests with that method is the
   same as the effect for a single such request.  Of the request methods
   defined by this specification, PUT, DELETE, and safe request methods
   are idempotent.
  • ์‹ค์ œ HTTP ๋ช…์„ธ ๋ฌธ์„œ์— ๋”ฐ๋ฅด๋ฉด ๋ฉฑ๋“ฑ์„ฑ์„ ๊ฐ–๋Š” ๋ฉ”์†Œ๋“œ๋ž€ ํ–‰์œ„๋ฅผ ํ•œ๋ฒˆ ์š”์ฒญํ–ˆ์„๋•Œ์™€ ๋‹ค๋Ÿ‰์œผ๋กœ ์š”์ฒญํ–ˆ์„ ๋•Œ๊ฐ€ ๊ฐ™์€ ํšจ๊ณผ๊ฐ€ ๋‚˜๋Š” ๊ฒƒ์ด๋ผ๊ณ  ํ•œ๋‹ค.      
  • Data์˜ ์ƒํƒœ๋ฅผ ์ƒ๊ฐํ•ด๋ณด์ž. 
    • ํ•จ์ˆ˜์˜ ํ˜•ํƒœ๋กœ ํ‘œํ˜„ํ•˜๋ฉด F(F(x))=F(x) ์œผ๋กœ ์ดํ•ดํ•˜๋ฉด ์‰ฝ๋‹ค.
    • 1๋ฒˆ ์œ ์ €๋ฅผ ํ•œ๋ฒˆ ์ง€์šฐ๊ฑฐ๋‚˜, ์—ฌ๋Ÿฌ๋ฒˆ ์ง€์šฐ๋Š” ์š”์ฒญ์„ ํ•ด๋„ 1๋ฒˆ ์œ ์ €๊ฐ€ ์—†๋Š” ์ƒํƒœ๋Š” ๊ฐ™๋‹ค.
  • ๋ฉฑ๋“ฑ์„ฑ์„ ๊ฐ€์ง€๋Š” ๋ฉ”์†Œ๋“œ
    • GET/ HEAD/ OPTIONS : ๋ฉฑ๋“ฑ์„ฑ๋„ ๊ฐ€์ง€๋ฉฐ, ์„œ๋ฒ„์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š์•„ SAFEํ•œ ์š”์ฒญ์ด๊ธฐ๋„ ํ•˜๋‹ค.
    • PUT/PATCH/DELETE 
      • ๋ฆฌ์†Œ์Šค์˜ ์œ„์น˜๋ฅผ ์ •ํ™•ํ•˜๊ฒŒ ์ง€์ •ํ•˜์—ฌ ์žฌ์š”์ฒญ์„ ํ–ˆ์„ ๊ฒฝ์šฐ, ๋ฆฌ์†Œ์Šค ์ˆ˜์ •/์‚ญ์ œ ๋“ฑ์˜ ๋™์ผํ•œ ๊ฒฐ๊ณผ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค. 
      • ํ•˜๋‚˜์˜ ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•ด์„œ๋งŒ ์ˆ˜์ •/์‚ญ์ œ๋“ฑ์„ ์ผ์œผํ‚ค๊ณ , ๋”์ด์ƒ ๋˜‘๊ฐ™์€ ์š”์ฒญ์— ๋Œ€ํ•ด์„œ๋Š” ๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ์˜ ๋ณ€๊ฒฝ์„ ์ผ์œผํ‚ค์ง€ ์•Š๋Š”๋‹ค.
    • POST
      • ๋งŒ์•ฝ POST๋ฅผ ์—ฌ๋Ÿฌ๋ฒˆ ์žฌ์š”์ฒญํ–ˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ด๋ณด์ž.
      • POST๋ฅผ ํ•œ๋ฒˆ ์š”์ฒญํ•˜๋Š” ๊ฒƒ๊ณผ ๋‹ค๋Ÿ‰์œผ๋กœ ์š”์ฒญํ•˜๋Š” ๊ฒƒ์€ ๋ฆฌ์†Œ์Šค๋ฅผ ๊ณ„์† ์ƒˆ๋กœ ์ƒ์„ฑํ•˜๋Š”๊ฒƒ๊ณผ ํ•œ๊ฐœ๋งŒ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ์˜ ์ฐจ์ด์ ์„ ๊ฐ€์ง„๋‹ค. ์ฆ‰ POST์˜ ์žฌ์š”์ฒญ์‹œ์— ์„œ๋ฒ„์˜ ์ƒํƒœ๋Š” 1๋ฒˆ ์š”์ฒญํ–ˆ์„ ๋•Œ์˜ ์„œ๋ฒ„์˜ ์ƒํƒœ์™€ ๋‹ค๋ฅด๋‹ค.
  • ์„œ๋ฒ„์˜ ์ƒํƒœ๊ฐ€ ์œ ์ง€๋œ๋‹ค๋Š” ๊ฐœ๋…์ด ์ƒ๋‹นํžˆ ํ—ท๊ฐˆ๋ฆด ์ˆ˜ ์žˆ๋‹ค. ํ•„์ž์˜ ๊ฒฝ์šฐ์—๋„ "์ˆ˜์ •์„ ๊ณ„์† ํ•˜๋ฉด ๋งค๋ฒˆ ์„œ๋ฒ„ ์ƒํƒœ๊ฐ€ ๋‹ค๋ฅธ ๊ฑฐ ์•„๋ƒ???" ๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ด๋Š” ๋งค๋ฒˆ ๋‹ค๋ฅธ ์ˆ˜์ • ์š”์ฒญ์„ ๋ณด๋‚ผ ๋•Œ์˜ ๊ฒฝ์šฐ์ด๋ฉฐ, ๋งค๋ฒˆ "๋™์ผํ•œ" ์š”์ฒญ์„ ํ–ˆ์„๋•Œ, ๋ฐ์ดํ„ฐ์˜ ์ƒํƒœ๊ฐ€ ๋ณ€๊ฒฝ๋œ๋‹ค๋ฉด ๋ฉฑ๋“ฑ์„ฑ์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋ฉด ์‰ฝ๋‹ค.

 

๐ŸฅŠPUT VS PATCH

PATCH์™€ PUT์€ ๋‘˜ ๋‹ค ๋ฐ์ดํ„ฐ์˜ ์ˆ˜์ •์„ ์œ„ํ•œ method์ด์ง€๋งŒ, ์–ด๋– ํ•œ ๋ฐฉ์‹์œผ๋กœ ๋ฆฌ์†Œ์Šค๋ฅผ ์ˆ˜์ •ํ•˜๋Š”์ง€๊ฐ€ ๋‹ค๋ฅด๋‹ค.

  • PATCH, which is used to apply partial modifications to a resource
  • PUT method requests that the state of the target resource be created or replaced with the state defined by the representation enclosed in the request message payload

์ฆ‰, PUT ๋ฉ”์†Œ๋“œ๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ๊ฐ€์ง„ ์†์„ฑ์— ๋Œ€ํ•œ ์š”์ฒญ์„ ์ผ๋ถ€๋ถ„๋งŒ ๋ณด๋‚ธ ๊ฒฝ์šฐ์—๋Š” ์ „๋‹ฌํ•œ ํ•„๋“œ ์ด์™ธ์˜ ๊ฐ’์ด ๋ชจ๋‘ null ๋˜๋Š” default ๊ฐ’์œผ๋กœ ์ฒ˜๋ฆฌ๋˜์–ด ๋ฒ„๋ฆฐ๋‹ค.

 

๊ทธ๋Ÿฌ๋‚˜, PATCH๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ณ€๊ฒฝํ•  ์†์„ฑ์— ๊ด€ํ•ด์„œ๋งŒ ์š”์ฒญ์„ ๋ณด๋‚ด๋ฉด, ์ƒˆ๋กญ๊ฒŒ ๋ฐ”๋€ ๋ถ€๋ถ„๋งŒ ๋ฐ˜์˜๋˜๋ฉฐ ๋‚˜๋จธ์ง€๋Š” ๊ธฐ์กด์˜ ๋ฐ์ดํ„ฐ๊ฐ€ ์œ ์ง€๋œ๋‹ค.

-> ์ฆ‰ ์ž์›์˜ ์ผ๋ถ€๋ฅผ ์ˆ˜์ •ํ• ๋•Œ๋Š” PATCH ๋ฉ”์†Œ๋“œ๋ฅผ, ์ „์ฒด์ ์ธ ์ˆ˜์ •์ด ํ•„์š”ํ•  ๋•Œ๋Š” PUT ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋œ๋‹ค.


-์ด๋ ‡๊ฒŒ REST API ์„ค๊ณ„์‹œ ์ค‘์š”ํ•œ ๋‘ ๊ฐ€์ง€ ์›์น™์„ ๊ธฐ์–ตํ•˜๋ฉด์„œ URI ์„ค๊ณ„์‹œ ๋ฐ˜๋“œ์‹œ ์•Œ์•„์•ผํ•  ๊ฐ€์ด๋“œ๋ผ์ธ์„ ์‚ดํŽด๋ณด์ž.

 

1. ์†Œ๋ฌธ์ž๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

  • ์ฃผ์†Œ์—์„œ ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•˜๋ฏ€๋กœ, ์นด๋ฉœํ˜•์‹์ด ์•„๋‹Œ ์†Œ๋ฌธ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ž‘์„ฑํ•œ๋‹ค.
- BAD CASE
<http://restapi.com/users/postComments>

- GOOD CASE
<http://restapi.com/users/post-comments>

 

2. ์–ธ๋”๋ฐ” ๋Œ€์‹  ํ•˜์ดํ”ˆ์„ ์‚ฌ์šฉํ•œ๋‹ค.

  • ๊ฐ€๊ธ‰์ ์ด๋ฉด ํ•˜์ดํ”ˆ๋„ ์ƒ๋žตํ•ด์•ผ ํ•˜๋Š” ์ด์œ ๋Š”, ์ฃผ์†Œ์ฐฝ์— ๊ฐ€๋ ค์ ธ ์‚ฌ์šฉ์ž๊ฐ€ ํ™•์ธํ•˜๊ธฐ ์–ด๋ ค์šธ์ˆ˜๋„ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.
- BAD CASE
<http://restapi.com/users/post_comments>

- GOOD CASE
<http://restapi.com/users/post-comments>

 

3. ๋งˆ์ง€๋ง‰์— ์Šฌ๋ž˜์‹œ๋ฅผ ํฌํ•จํ•˜์ง€ ์•Š๋Š”๋‹ค.

  • ์Šฌ๋ž˜์‹œ๋Š” ๊ณ„์ธต์„ ๊ตฌ๋ถ„ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๋งˆ์ง€๋ง‰์—๋Š” ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.

 

4. ํ–‰์œ„๋Š” ํฌํ•จํ•˜์ง€ ์•Š๋Š”๋‹ค.

  • ํ–‰์œ„๋Š” URL ๋Œ€์‹  HTTP Method๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ „๋‹ฌํ•œ๋‹ค.
- BAD CASE
<http://restapi.com/users/1/delete-post/1>

- GOOD CASE
<http://restapi.com/users/1/posts/1>

 

5. ํŒŒ์ผ ํ™•์žฅ์ž๋Š” URI์— ํฌํ•จํ•˜์ง€ ์•Š๋Š”๋‹ค.

  • REST API์—์„œ๋Š” ๋ฉ”์„ธ์ง€ ๋ฐ”๋”” ๋‚ด์šฉ์˜ ํฌ๋งท์„ ๋‚˜ํƒ€๋‚ด๊ธฐ ์œ„ํ•œ ํŒŒ์ผ ํ™•์žฅ์ž๋Š” URI ์•ˆ์— ํฌํ•จํ•˜์ง€ ์•Š๋Š”๋‹ค.
- BAD CASE 
<http://restapi.com/users/photo.jpg> 

- GOOD CASE 
GET <http://restapi.example.com/users/photo> HTTP/1.1 
Host: restapi.example.com Accept: image/jpg

 

6. ๊ฐ€๊ธ‰์  ์ „๋‹ฌํ•˜๊ณ ์ž ํ•˜๋Š” ์ž์›์˜ ๋ช…์‚ฌ๋ฅผ ์‚ฌ์šฉํ•˜๋˜, ์ปจํŠธ๋กค ์ž์›์„ ์˜๋ฏธํ•˜๋Š” ๊ฒฝ์šฐ ์˜ˆ์™ธ์ ์œผ๋กœ ๋™์‚ฌ๋ฅผ ํ—ˆ์šฉํ•œ๋‹ค.

  • ํ•ญ์ƒ Resource๊ฐ€ ์–ด๋–ค ๋ฒ”์ฃผ์— ํฌํ•จ๋˜์–ด์žˆ๋Š”์ง€ ํ™•์ธํ•ด์•ผ ํ•œ๋‹ค.
  • ์ปจํŠธ๋กค ์ž์›์˜ ๊ฒฝ์šฐ์—๋Š” ๋™์‚ฌ๋ฅผ ์ง์ ‘ ์‚ฌ์šฉํ•ด์„œ ์ด๋ฆ„์„ ์ง“๋Š”๋‹ค.
  • ๋งŒ์•ฝ ๊ฐ€์šฉํ•  ์ˆ˜ ์žˆ๋Š” HTTP method๊ฐ€ GET,POST๋กœ ํ•œ์ •๋œ ๊ฒฝ์šฐ์—๋Š” ์ปจํŠธ๋กค URI๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— delete๋“ฑ์˜ ๋™์‚ฌ๋กœ URI๋ฅผ ์„ค๊ณ„ํ•˜๊ธฐ๋„ ํ•œ๋‹ค.
http://api.example.com/cart-management/users/{id}/cart/checkout
http://api.example.com/song-management/users/{id}/playlist/play