-
Notifications
You must be signed in to change notification settings - Fork 1
API 명세서
Minjae An edited this page Oct 5, 2024
·
5 revisions
Autorization: Bearer {access_token}
- 인가가 필요한 API에 요청 시
Authorization
request header 필수 - access token(JWT)를 통해 인가 수행, Bearer 토큰 형식
{
"message": "사용자가 존재하지 않음"
}
- 비즈니스 로직상 예외 - 예외 상황 메시지 제공
{
"message": {
"birth": "생년월일은 필수값",
"gender": "성별은 필수값"
}
}
- 요청값 예외 :
문제의 요청 필드명 : 예외 메시지
와 같은Map
형태로 제공
마지막 슬래시는 불필요하며 일관성을 해친다.
http://api.example.com/users
http://api.example.com/users/
하이픈이 URL에서 가장 가독성이 좋다.
http://api.example.com/talk-topics
http://api.example.com/talk_topics
대소문자 구분으로 인한 혼란을 방지한다.
http://api.example.com/user-profiles
http://api.example.com/User-Profiles
HTTP 메서드가 동작을 나타내므로 URL에는 리소스만 표현한다. (예외 존재)
http://api.example.com/user-profiles
http://api.example.com/User-Profiles
확장자 대신 Accept 헤더를 사용한다.
GET /users/123/profile
Accept: image/png
GET /users/123/profile.png
일관성을 위해 리소스 컬렉션은 복수형을 사용한다.
GET /articles
GET /article
URL 구조를 단순하게 유지하고 유연성을 제공한다.
GET /articles?sort=date&filter=published
GET /articles/sort/date/filter/published
HTTP 메서드가 동작을 나타내므로 중복을 피한다.
POST /articles
POST /articles/create
리소스 간의 관계를 명확히 표현한다.
GET /users/123/articles
GET /articles?userId=123
HTTP 상태 코드로 요청 결과를 명확히 전달한다.
- 요청이 정상 수행되었으며 응답 데이터가 존재 :
200 OK
- 잘못된 요청 값이 요청에 포함됨 :
400 Bad Request
항상 200 OK
사용
클라이언트에게 응답 형식 정보를 제공한다.
Content-Type : application/json
헤더 없이 응답
클라이언트가 에러를 쉽게 처리할 수 있게 한다.
{"error": "Invalid token", "code": "AUTH001"}
비일관적인 에러 응답 형식
대량의 데이터를 효율적으로 처리할 수 있게 한다.
GET /articles?page=2&per_page=100
페이지 정보 없는 대량 데이터 응답