RESTful์ ์๋ฏธ
REST์ ์ด๋ค, REST์ค๋ฝ๋ค
๊ทธ๋ผ, REST๋ ๋ฌด์?
REST (Representational State Transfer)
์ํค REST
์)
Post/user
Get/user1
Get/users
Delete/user1!
: Designing Consistent RESTful Web Service Interfaces
ํ์ฌ์์ ์ฅ๊ณ ๋ก ๋ ์จ ์ ๋ณด๋ฅผ ์ ๊ณตํ๋ API๋ฅผ ์์ฑํ๋ ์
๋ฌด๋ฅผ ๋งก์๋ค.
query string์ 'ํ์ดํ(-)์ ์จ์ผํ๋? ์ธ๋๋ฐ(_)๋ฅผ ์จ์ผํ๋?' ์๋ฌธ์ด ๋ค์ด์ ๊ตฌ๊ธ๋ง์ ํ๋๋ฐ.
๊ตฌ๊ธ SEO์ด์๋ก ํ์ดํ์ ์ฐ๋ผ๋ ์๊ฒฌ์ด ๋ง์๋ค.
๊ทธ๋ฆฌ๊ณ ์์ ์ฑ
์ ์๊ฐํ๋ ๊ธ์ ๋ฐ๊ฒฌํ๋ค.
๊ตญ๋ด์์ ์๋ ebook์์ด์
์๋ง์กด์์ kindle์ฉ ebook์ผ๋ก ๊ตฌ๋งคํ๋ค.
์ด์ ์ฝ์ด๋ณด์!
A REST Application Programming Interface (REST API) is a type of web server that enables a client, either user-operated or automated, to access resources that model a systemโs data and functions.
Masse, Mark. REST API Design Rulebook (p. 4). O'Reilly Media. Kindle Edition.
1) Hello World Wide Web
On August 6, 1991, on the Webโs first page, Berners-Lee wrote, The WorldWideWeb (W3) is a wide-area hypermedia information retrieval initiative aiming to give universal access to a large universe of documents.[10]
Masse, Mark. REST API Design Rulebook (p. 10). O'Reilly Media. Kindle Edition.
2) Key constraints:
3) Web Standards
4) REST
5) REST APIs
"a set of design rules for REST API URIs"
1) URI (Uniform Resource Identifier)
Tim Berners-Lee included a note about the opacity of URIs in his โAxioms of Web Architectureโ list:
The only thing you can use an identifier for is to refer to an object. When you are not dereferencing, you should not look at the contents of the URI string to gain other information. โ Tim Berners-Lee
http://www.w3.org/DesignIssues/Axioms.html
Masse, Mark. REST API Design Rulebook (p. 22). O'Reilly Media. Kindle Edition.
2) URI format
The rules presented in this section pertain to the format of a URI. RFC 3986[19] defines the generic URI syntax as shown below:
URI = scheme "://" authority "/" path [ "?" query ] [ "#" fragment ]
Masse, Mark. REST API Design Rulebook (pp. 22-23). O'Reilly Media. Kindle Edition.
Rule 1. ๊ณ์ธต ๊ด๊ณ๋ฅผ ๋ํ๋ผ ๋๋ "/" ๋ฐ๋์ ์ฌ์ฉ
Rule 2. URI์๋ ํธ๋ ์ผ๋ง ์ฌ๋ฌ์("/") ์ฌ์ฉ ๋ถํ์
Rule 3. ํ์ดํ("-")์ ์ฌ์ฉํ๋ฉด URI ๊ฐ๋
์ฑ์ด ์ฆ๊ฐ๋จ
Rule 4. ์ธ๋์ค์ฝ์ด("_")๋ URI์ ์ฌ์ฉํ์ง ๋ง ๊ฒ
Rule 5. URI ๊ฒฝ๋ก์๋ ์๋ฌธ์๊ฐ ๋ ์ ํธ๋จ
- ๋๋ฉ์ธ ์ด๋ฆ์ ๋์๋ฌธ์ ์๊ด์๋๋ฐ
- ๋๋ฉ์ธ์ ์ ์ธํ URI๋ ๋์๋ฌธ์๋ฅผ ๊ตฌ๋ถํด์ฉ!
RFC 3986 defines URIs as case-sensitive except for the scheme and host components. For example:
(1) http://api.example.restapi.org/my-folder/my-doc
(2) HTTP://API.EXAMPLE.RESTAPI.ORG/my-folder/my-doc
(3) http://api.example.restapi.org/My-Folder/my-doc
(1) This URI is fine.
(2) The URI format specification (RFC 3986) considers this URI to be identical to URI #1.
(3) This URI is not the same as URIs 1 and 2, which may cause unnecessary confusion.
Masse, Mark. REST API Design Rulebook (p. 24). O'Reilly Media. Kindle Edition.
Rule 6. ํ์ผ ํ์ฅ์๋ URI ํฌํจํ์ง ๋ง ๊ฒ
- REST API์์๋ URI ํ์ผ ํ์ฅ์๋ฅผ ํ์ํ์ง ์์์
- ํ์ผ์ด ์ด๋ค ์ข
๋ฅ์ ํ์ผ์ธ์ง๋ HTTP์ Content-Type ํค๋์์ ๋ฏธ๋์ด ํ์
์ ํตํด ์๋ ค์ฃผ์ง์!
3) URI Authority Design
๋ค์ด๋ฐ ์ปจ๋ฒค์
๋ถ๋ถ!
Rule 1. API๋ฅผ ์ํด์ ์ผ๊ด์ ์ธ ์๋ธ๋๋ฉ์ธ ์ด๋ฆ ์ฌ์ฉํ ๊ฒ
Rule 2. ํด๋ผ์ ๊ฐ๋ฐ์ ํฌํธ์ ์ํด์ ์ผ๊ด์ ์ธ ์๋ธ๋๋ฉ์ธ ์ด๋ฆ ์ฌ์ฉํ ๊ฒ
4) Resource Modeling
5) Resource Archetypes
1. Document
2. Collection : ์๋ฒ๊ฐ ๊ด๋ฆฌํ๋ ๋ฆฌ์์ค๋ค์ "๋๋ ํฐ๋ฆฌ"
3. Store : ํด๋ผ์ด์ธํธ ๊ด๋ฆฌํ๋ ๋ฆฌ์์ค๋ค์ "์ ์ฅ์"
4. Controller : ํจ์์ฒ๋ผ ์ธํ๊ณผ ์์ํ์ด ์์
"storeํ๊ณ controller์ ๊ฐ๋
์๋ฆฌ์ก์กํ๋ค -_-"
6) URI Path Design
Rule 1. ์ปฌ๋ ์
์ด๋ฆ์ผ๋ก๋ ๋ณต์๋ฅผ ์ฌ์ฉํ ๊ฒ
Rule 2. ์คํ ์ด ์ด๋ฆ์ผ๋ก๋ ๋ณต์๋ฅผ ์ฌ์ฉํ ๊ฒ
Rule 3. ์ปจํธ๋กค๋ฌ ์ด๋ฆ์ผ๋ก๋ ๋์ฌ/๋์ฌ๊ตฌ ์ฌ์ฉํ ๊ฒ
Rule 4. ๋ณ๋์ด ์๋ ๊ฒฝ๋ก ์ธ๊ทธ๋จผํธ๋ ID๊ธฐ๋ฐ์ ๊ฐ์ผ๋ก ๋์ฒด ๊ฐ๋ฅ
Rule 5. CRUD ๊ธฐ๋ฅ์ด๋ฆ์ URI์ ์ฌ์ฉํ์ง ๋ง ๊ฒ
7) URI Query Design
Rule 1. URI์ ์ฟผ๋ฆฌ ์ปดํฌ๋ํธ๋ ์ปฌ๋ ์
๋๋ ์คํ ์ด๋ฅผ filterํ๋๋ฐ ์ฌ์ฉ๋ ์ ์์
Rule 2. URI์ ์ฟผ๋ฆฌ ์ปดํฌ๋ํธ๋ ์ปฌ๋ ์
๋๋ ์คํ ์ด์ ๊ฒฐ๊ณผ๋ฅผ paginateํ๋๋ฐ ์ฌ์ฉ๋ ์ ์์