Spring/mybatis

[springboot / 게시판 API] Data Input & Output ver 0.1

dev_rosieposie 2023. 9. 17. 17:33

Goal 

  1. 요청데이터와 응답데이터 및 HTTP 상태코드를 디자인 해보자

API를 디자인 했으니, 해당 API가 작동시 요청 데이터와 응답데이터를 미리 디자인 해보자!

 HTTP 상태코드란 ? 

클라이언트가 보낸 요청의 처리 상태를 응답에서 알려주는 기능이다

 

자세한 내용은 아래 포스팅 참고!

https://dev-rosiepoise.tistory.com/123

 

[네트워크] HTTP 상태코드 (2xx - 성공, 3xx - 리다이렉션, 4xx - 클라이언트 오류, 5xx - 서버 오류)

Goal HTTP 상태코드에 대해서 알아본다 2xx 성공코드에 대해 알아본다 3xx 리다이렉션 코드에 대해 알아본다 PRG post redirect get 에 대해 알아본다 4xx 클라이언트 오류에 대해 알아본다 5xx 서버 오류에

dev-rosiepoise.tistory.com

 

그럼 디자인 한 일부를 살펴보자

1차 data input & output design 

기능 uri 요청 응답
회원 권한 등록 기능 /authority POST /authority HTTP/1.1
Content-Type:application/json

{
"authNm" : "gold",
"level" : 1
}


성공시 

POST /authority HTTP/1.1 
201 Created
Content-Type:application/json
Content-Length:
Location: /authority/1
{
"authId" : 1 ,
"authNm" : "gold",
"level" : 1,
"useYn" : true,
"regDt" : 2023-09-09
}

// 권한id, 권한명, 사용여부, 레벨, 등록일자
실패시

HTTP/1.1 400 Bad Request

{
"errors": {
"message": "'name'(body) must be String, input 'name': 123",
"detail": [
{
"location": "body",
"param": "authNm",
"value": 123,
"error": "TypeError",
"msg": "문자여야만 합니다."
}
]
}
}


회원 권한 목록 조회 기능 /authoritys GET /authoritys?offset=50 HTTP/1.1
Host: localhost:8080

// offset, 조회조건
GET /authoritys HTTP/1.1 200 OK
Content-Type:application/json
Content-Length:
[
{
"authId" : 1 ,
"authNm" : "gold",
"level" : 1 ,
"useYn" : true,
"regDt" : 2023-09-09
},
{
"authId" : 1 ,
"authNm" : "pink",
"level" : 3 ,
"useYn" : true,
"regDt" : 2023-09-09
}
]
// 권한id, 권한명, 사용여부, 레벨, 등록일자


회원 권한 상세 조회 기능 /authority/{auth-id} GET /authority?authId=1 HTTP/1.1
Host: localhost:8080

//권한id
GET /authority HTTP/1.1 200 OK
Content-Type:application/json
Content-Length:
{
"authId" : 1 ,
"authNm" : "gold",
"level" : 1 ,
"useYn" : true,
"regDt" : 2023-09-09,
"mdfDt" : 2023-09-09
}
//권한id, 권한명, 사용여부, 레벨,등록일자, 수정일자


회원 권한 수정 기능 /authority/{auth-id} PUT /authority/1 HTTP/1.1
Content-Type:application/json

{
"authNm" : "silver"
}


// 권한명, 레벨
PUT/authority/1 201 Created
{
"authNm" : "gold",
"level" : 2,
"useYn" : true,
"regDt" : 2023-09-09,
"mdfDt" : 2023-09-09
}


// 권한명, 레벨, 수정일자
회원 권한 삭제 기능 /authority/{auth-id} DELETE /user/1 HTTP/1.1
Host: localhost:8080

// 회원id
// 성공시
HTTP/1.1 200 OK or 204 No Content

"정상적으로 삭제되었습니다"

// 실패시
HTTP/1.1 400 Bad Request
{
"errors": {
"message": "이미 삭제된 _ 입니다."
}
}

회원 중복 조회 기능 /user/check-duplicate/{login-id} GET /user/check-duplicate?loginId=rosie128 HTTP/1.1
Host: localhost:8080

// 로그인id
// 성공시
GET /user/user-duplicate HTTP/1.1200 OK

// 실패시
HTTP/1.1 400 Bad Request
{
"errors": {
"message": "이미 존재하는 id 입니다.",
"detail": [
{
"location": "body",
"param": "loginId",
"value": "rosie128",
"error": "DuplicatedError",
"msg": "이미 존재하는 id 입니다."
}
]
}
}

로그인
기능
/login/{login-id}

or

/user/login/{login-id}
POST /login/rosiekim128 HTTP/1.1
Host: localhost:8080

// 로그인id
// 성공시
POST /login/rosiekim128 HTTP/1.1200 OK

토큰

Content-Type:application/json
Content-Length:
{
"userId" : 1 ,
"loginId" : "rosie128",
"pwd" : "tt1234" ,
"name" : "김다슬",
"email" : "rosie@gmail.com"
}

// 회원id, 로그인id, 비밀번호, 이름, 이메일

// 실패시
HTTP/1.1 400 Bad Request
{
"errors": {
"message": "'일치하지 않는 id, password 입니다.",
"detail": [
{
"location": "body",
"error": "IncorrectError",
"msg": "일치하지 않는 id, password 입니다."
}
]
}
}

공통   잘못된 URI 접근 HTTP/1.1 404 Not Found
"잘못된 경로의 접근입니다"
    클라이언트가 권한(인증) 없어 작업을 진행할 수 없는 경우 HTTP/1.1 401 Unauthorized
로그인이 필요합니다
    클라이언트가 권한이 없어 작업을 진행할 수 없는 경우 HTTP/1.1 403 Forbidden
gold level부터 접근이 가능합니다