1 분 소요

RESTFUL

REST 6가지 규칙 ( REpresentational State Transfer )

1. Client-Server 구조

  • 클라이언트와 서버는 서로 독립적
  • 클라이언트는 오직 URLs 리소스만 알아야 한다.

2. Stateless

  • 클라이언트의 모든 요청에는 해당 Request를 이해할 수 있는 모든 정보가 포함되어야 한다.

3. Cacheable

  • 서버는 Response cache-control 해더에 해당 요청이 캐싱이 가능한지에 대한 여부를 제공해야 한다.

4. Uniform interface

  • 보편적인 소프트웨어 엔지니어링 원칙을 component interface에 적용하면, 전체적인 시스템 아키텍처는 단순화 되고 각 상호작용에 대한 가시성이 개선

5. Layered system

  • REST는 다중 계층 구조를 가질 수 있도록 허용

6. Code on demand ( optional )

  • 서버가 클라이언트에서 실행시킬 수 있는 로직을 전송하여 클라이언트의 기능을 확장 시킬 수 있다.

RESTFul 7가지 네이밍 규칙

1. 소문자를 사용한다.

  • 현업에서는 잘 어겨지긴 한다.. ㅎ
  • 딱히 크게 상관 없음 . 단지 이러면 좋다 이런 느낌. 좀더 restful하게 개발한다 ~
Bad	http://restapi.example.com/users/postComments
Good	http://restapi.example.com/users/post-comments

2. 언더바를 대신 하이픈을 사용한다.

Bad	http://restapi.example.com/users/post_comments
Good	http://restapi.example.com/users/post-comments

3. 마지막에 슬래시를 포함하지 않는다. ( 절대 )

Bad	http://restapi.example.com/users/
Good	http://restapi.example.com/users

4. 행위는 포함하지 않는다.

  • 금융권이나 레거시 코드를 많이 사용하는 곳에는 post로 다 사용해야하기 때문에 잘 어긴다.
  • 레거시 코드란 다른 사람에게 넘겨받은 읽기 어렵고 수정하기 어려운 오래된 코드이다.
Bad	POST   http://restapi.example.com/users/1/delete-post/1
Good	DELETE http://restapi.example.com/users/1/posts/1

5. 파일 확장자는 URI에 포함하지 않는다.

Bad	http://restapi.example.com/users/photo.jpg
Good	GET http://restapi.example.com/users/photo HTTP/1.1 Host: restapi.example.com Accept: image/jpg

6. 가급적 전달하고자하는 자원의 명사를 사용하되, 컨트롤 자원을 의미하는 경우 예외적으로 동사를 허용한다.

Bad	http://restapi.example.com/posts/duplicating
Good	http://restapi.example.com/posts/duplicate

7. URI에 작성되는 영어를 복수형으로 작성한다. ( 개념적 Tree 구조 )

Bad	http://restapi.example.com/student/course
Good	http://restapi.example.com/students/3248234/courses
Good	http://restapi.example.com/students/3248234/courses/physics