(CS/컴퓨터공학) REST API 디자인 기본 규칙

✨ 개요

REST는 “HTTP를 일관된 규약으로 잘 쓰자”가 핵심입니다.
아래 체크리스트를 따르면 클라이언트(Android/iOS/Web/서버) 모두가 예측 가능하고


1. 리소스 설계 & 경로 규칙


2 HTTP 메서드 의미(정리표)

메서드 의미 멱등성 예시
GET 조회 GET /users?role=admin
POST 생성/행위 ❌(보통) POST /orders
PUT 전체 교체 PUT /profiles/{id}
PATCH 부분 수정 ❌/준멱등 PATCH /profiles/{id}
DELETE 삭제 DELETE /orders/{id}

멱등성을 지켜야 재시도/중복요청에서도 안전합니다.


3 상태코드 사용 원칙


4. 표현(Representation) & 콘텐츠 협상


5. 버저닝(Versioning)


6. 페이징/정렬/필터


7. 생성/업데이트 요청 바디


8. 멱등키(Idempotency-Key) & 재시도


9. 에러 응답 표준화 (RFC 7807 권장)


10. 동시성 제어 & 조건부 요청


11. 캐싱 전략


12. 보안(필수)


13. 최소 예시(생성 -> 조회)

POST /v1/orders
Content-Type: application/json
Idempotency-Key: 5f6b-12ab

{
  "userId": "u_123",
  "items": [{"sku":"A12","qty":2}]
}
201 Created
Location: /v1/orders/o_987
Content-Type: application/json
ETag: "v1"
X-Request-Id: 83f2f9f0

{
  "id": "o_987",
  "status": "PENDING",
  "userId": "u_123",
  "items": [{"sku":"A12","qty":2}],
  "createdAt": "2025-11-24T07:10:00Z",
  "links": { "self": "/v1/orders/o_987" }
}
422 Unprocessable Entity
Content-Type: application/problem+json
X-Request-Id: 83f2f9f0

{
  "type": "https://api.example.com/problems/validation-error",
  "title": "Validation failed",
  "status": 422,
  "detail": "items[0].qty must be >= 1",
  "errors": { "items[0].qty": "must be >= 1" }
}


Related Posts