Skip to content

Latest commit

ย 

History

History
87 lines (52 loc) ยท 2.46 KB

[Web] REST API.md

File metadata and controls

87 lines (52 loc) ยท 2.46 KB

REST API


REST : ์›น (HTTP) ์˜ ์žฅ์ ์„ ํ™œ์šฉํ•œ ์•„ํ‚คํ…์ณ

1. REST (REpresentational State Transfer) ๊ธฐ๋ณธ

  • REST์˜ ์š”์†Œ

    • Method

      Method ์˜๋ฏธ Idempotent
      POST Create No
      GET Select Yes
      PUT Update Yes
      DELETE Delete Yes

      Idempotent : ํ•œ ๋ฒˆ ์ˆ˜ํ–‰ํ•˜๋ƒ, ์—ฌ๋Ÿฌ ๋ฒˆ ์ˆ˜ํ–‰ํ–ˆ์„ ๋•Œ ๊ฒฐ๊ณผ๊ฐ€ ๊ฐ™๋‚˜?


    • Resource

      • http://myweb/users์™€ ๊ฐ™์€ URI
      • ๋ชจ๋“  ๊ฒƒ์„ Resource (๋ช…์‚ฌ)๋กœ ํ‘œํ˜„ํ•˜๊ณ , ์„ธ๋ถ€ Resource์—๋Š” id๋ฅผ ๋ถ™์ž„

    • Message

      • ๋ฉ”์‹œ์ง€ ํฌ๋งท์ด ์กด์žฌ

        : JSON, XML ๊ณผ ๊ฐ™์€ ํ˜•ํƒœ๊ฐ€ ์žˆ์Œ (์ตœ๊ทผ์—๋Š” JSON ์„ ์”€)

        HTTP POST, http://myweb/users/
        {
        	"users" : {
        		"name" : "terry"
        	}
        }
        

  • REST ํŠน์ง•

    • Uniform Interface

      • HTTP ํ‘œ์ค€๋งŒ ๋งž๋Š”๋‹ค๋ฉด, ์–ด๋–ค ๊ธฐ์ˆ ๋„ ๊ฐ€๋Šฅํ•œ Interface ์Šคํƒ€์ผ

        ์˜ˆ) REST API ์ •์˜๋ฅผ HTTP + JSON๋กœ ํ•˜์˜€๋‹ค๋ฉด, C, Java, Python, IOS ํ”Œ๋žซํผ ๋“ฑ ํŠน์ • ์–ธ์–ด๋‚˜ ๊ธฐ์ˆ ์— ์ข…์† ๋ฐ›์ง€ ์•Š๊ณ , ๋ชจ๋“  ํ”Œ๋žซํผ์— ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•œ Loosely Coupling ๊ตฌ์กฐ

      • ํฌํ•จ

        • Self-Descriptive Messages

          • API ๋ฉ”์‹œ์ง€๋งŒ ๋ณด๊ณ , API๋ฅผ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋Š” ๊ตฌ์กฐ (Resource, Method๋ฅผ ์ด์šฉํ•ด ๋ฌด์Šจ ํ–‰์œ„๋ฅผ ํ•˜๋Š”์ง€ ์ง๊ด€์ ์œผ๋กœ ์ดํ•ดํ•  ์ˆ˜ ์žˆ์Œ)
        • HATEOAS(Hypermedia As The Engine Of Application State)

          • Application์˜ ์ƒํƒœ(State)๋Š” Hyperlink๋ฅผ ํ†ตํ•ด ์ „์ด๋˜์–ด์•ผ ํ•จ.
          • ์„œ๋ฒ„๋Š” ํ˜„์žฌ ์ด์šฉ ๊ฐ€๋Šฅํ•œ ๋‹ค๋ฅธ ์ž‘์—…์— ๋Œ€ํ•œ ํ•˜์ดํผ๋งํฌ๋ฅผ ํฌํ•จํ•˜์—ฌ ์‘๋‹ตํ•ด์•ผ ํ•จ.
        • Resource Identification In Requests

        • Resource Manipulation Through Representations

    • Statelessness

      • ์ฆ‰, HTTP Session๊ณผ ๊ฐ™์€ ์ปจํ…์ŠคํŠธ ์ €์žฅ์†Œ์— ์ƒํƒœ ์ •๋ณด ์ €์žฅ ์•ˆํ•จ

      • **Request๋งŒ Message๋กœ ์ฒ˜๋ฆฌ**ํ•˜๋ฉด ๋˜๊ณ , ์ปจํ…์ŠคํŠธ ์ •๋ณด๋ฅผ ์‹ ๊ฒฝ์“ฐ์ง€ ์•Š์•„๋„ ๋˜๋ฏ€๋กœ, ๊ตฌํ˜„์ด ๋‹จ์ˆœํ•ด์ง.

      • ๋”ฐ๋ผ์„œ, REST API ์‹คํ–‰์ค‘ ์‹คํŒจ๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ, Transaction ๋ณต๊ตฌ๋ฅผ ์œ„ํ•ด ๊ธฐ์กด์˜ ์ƒํƒœ๋ฅผ ์ €์žฅํ•  ํ•„์š”๊ฐ€ ์žˆ๋‹ค. (POST Method ์ œ์™ธ)

    • Resource ์ง€ํ–ฅ ์•„ํ‚คํ…์ณ (ROA : Resource Oriented Architecture)

      • Resource ๊ธฐ๋ฐ˜์˜ ๋ณต์ˆ˜ํ˜• ๋ช…์‚ฌ ํ˜•ํƒœ์˜ ์ •์˜๋ฅผ ๊ถŒ์žฅ.
    • Client-Server Architecture

    • Cache Ability

    • Layered System

    • Code On Demand(Optional)