URI 설계 원칙
- 슬래시 구분자(/)는 계층 관계를 나타내는데 사용한다.
ex) http://localhost:8080/user/search - URI 마지막 문자로(/)는 포함하지 않는다.
ex) http://localhost:8080/user/search/ <- 옳지않음 - 하이픈(-)은 URI 가독성을 높이는데 사용한다.
ex) http://localhost:8080/user/search/info-detail - 밑줄(_)은 사용하지 않는다.
ex) http://localhost:8080/user/search/info_detail - URI 경로에는 소문자가 적합하다.
- 파일 확장자는 URI에 포함하지 않는다.
ex) http://localhost:8080/user-information.jsp - 프로그래밍 언어에 의존적인 확장자를 사용하지 않는다.
ex) http://localhost:8080/user/search/info-detail.do - 구현에 의존적인 경로를 사용하지 않는다.
ex) http://localhost:8080/servlet/classes/java - 세션 ID를 포함하지 않는다.
ex) http://localhost:8080/user/search/info?sesstion-id=random - 프로그래밍 언어의 Method 명을 이용하지 않는다
ex) http://localhost:8080/user/search/info?action=intro - 명사에 단수형 보다는 복수형을 사용해야 한다. 컬렉션에 대한 표현은 복수로 사용한다.
ex) http://localhost:8080/classes/examples/user-info - 컨트롤러 이름으로는 동사나 동사구를 사용한다
ex) http://localhost:8080/user/search - 경로 부분 중 변하는 부분은 유일한 값으로 대체한다.
ex) .../examples/lessons/{lesson-id}/users/{user-id}
ex) .../examples/lessons/2/users/434 - CRUD 기능을 나타내는 것은 URI에 사용하지 않는다.
ex) .../examples/lessons/2/users/READ - URI Query Parameter 디자인 URI 쿼리 부분으로 컬렉션 결과에 대해서 필터링 할 수 있다.
- URI 쿼리는 컬렉션의 결과를 페이지로 구분하여 나타내는데 사용한다.
- API에 있어서 서브 도메인은 일관성 있게 사용해야 한다.
ex) https://google.com/
ex) https://api.google.com/
ex) https://api-google.com/ - 클라이언트 개발자 포탈 서브 도메인은 일관성 있게 만든다.
ex) http://dev-google.com/