본문 바로가기
인프라/HTTP

REST API URL 가이드

by bloodFinger 2021. 5. 24.

REST API 설계 시 가장 중요한 항목은 다음의 2가지로 요약할 수 있습니다.

첫 번째, URI는 정보의 자원을 표현해야 한다.
두 번째, 자원에 대한 행위는 HTTP Method(GET, POST, PUT, DELETE)로 표현한다.

 

ex) 

-회원 삭제
GET /members/delete/1   (x)
DELETE /members/1       (o)

-회원 조회
GET /members/show/1     (x)
GET /members/1          (o)

-회원 추가
GET /members/insert/2   (x)
POST /members/2         (o)

 

 

1. document 리소스
Use 'singular' name to denote document resource archetype.
(여기에서의 document는 하나의 객체를 생각하면 된다.)

http://restapi.com/managed-devices/{device-id}
http://restapi.com/members/{id}
http://restapi.com/members/admin

 

2. collection 리소스
Use the 'plural' name to denote the collection resource archetype.

(Collection 단위의 리소스를 표시할 때는 '복수'를 사용.)

http://restapi.com/managed-devices
http://restapi.com/members
http://restapi.com/members/{id}/accounts

 

3. store 리소스
Use 'plural' name to denote store resource archetype.
저장에 관한 요청은 클라이언트가 관리하는 리소스 저장소이다. 따라서 '복수'를 사용

http://restapi.com/members/{id}/playlists

 

4. controller 리소스
컨트롤러 리소스는 실행 가능한 기능과 함께 파라미터 혹은 리턴 값으로 이름 짓는다.
이 때는 '동사' 를 사용한다.

http://restapi.com/members/{id}/cart/checkout
http://restapi.com/members/{id}/playlist/play

 

 

URI 설계시 주의사항

1. 캬멜 표기법 X , 소문자 사용

2. 언더바 사용X  , 하이픈 사용

- 가급적 하이픈의 사용도 최소화하며, 정확한 의미나 표현을 위해 단어의 결합이 불가피한 경우에 사용한다.

3. 마지막에 슬래시 사용 X

4. 동사 대신 명사

 

5. 파일 확장자는 URI에 포함X

http://restapi.com/member.jpg.  (x)

 

 

 

 

 

 

 

 

참고 블로그: https://velog.io/@pm1100tm/%EA%B9%94%EB%81%94%ED%95%9C-URL-%ED%8C%A8%ED%84%B4%EC%9D%84-%EC%9C%84%ED%95%9C-REST-Resource-Naming-Guide

 

깔끔한 URL 패턴을 위한 REST Resource Naming Guide

해석이 틀리거나 할 수 있다.1\. A resource can be a singleton or a collection.하나의 리소스는 싱글턴 또는 컬랙션이 될 수 있다.singlton: 단 하나만 지칭할 때collection: 여러개를 합쳐서 지징할 때예를 들어 c

velog.io

'인프라 > HTTP' 카테고리의 다른 글

간단한 HTTP 프로토콜  (0) 2020.09.28