HTTP Methods

클라이언트와 서버 사이에 이루어지는 요청(Request)과 응답(Response) 데이터를 전송하는 방식입니다.

Method Content

GET

요청받은 URI의 정보를 검색하여 응답합니다.

POST

요청된 자원을 생성(CREATE) 합니다.

PUT

요청된 자원을 수정(UPDATE)한다. 리소스의 모든 것을 업데이트 합니다..

PATCH

PUT과 유사하게 요청된 자원을 수정(UPATE) 할 때 사용한다. 리소스의 일부를 업데이트 합니다.

DELETE

요청된 자원을 삭제할 것을 요청합니다.

HTTP status codes

모든 HTTP 응답 코드는 5개의 클래스(분류)로 구분된다. 상태 코드의 첫 번째 숫자는 응답의 클래스를 정의한다. 첫자리에 대한 5가지 값들은 다음과 같습니다:

1xx (정보): 요청을 받았으며 프로세스를 계속합니다.

2xx (성공): 요청을 성공적으로 받았으며 인식했고 수용합니다.

3xx (리다이렉션): 요청 완료를 위해 추가 작업 조치가 필요합니다.

4xx (클라이언트 오류): 요청의 문법이 잘못되었거나 요청을 처리할 수 없습니다.

5xx (서버 오류): 서버가 명백히 유효한 요청에 대해 충족을 실패습니다.

Status code Usage

200 OK

요청이 성공적으로 되었습니다.

201 Created

요청이 성공적이었으며 그 결과로 새로운 리소스가 생성되었습니다. 이 응답은 일반적으로 POST 요청 또는 일부 PUT 요청 이후에 따라옵니다.

400 Bad Request

이 응답은 잘못된 문법으로 인하여 서버가 요청을 이해할 수 없음을 의미합니다.

401 Unauthorized

이 응답은 "인증 되지 않음(unauthenticated)"을 의미합니다. 서버는 로그인이 필요한 페이지에 대해 이 요청을 제공할 수 있습니다.

409 Conflict

서버가 요청을 수행하는 중에 충돌이 발생했습니다. 서버는 응답할 때 충돌에 대한 정보를 포함해야 합니다.

USER API

1. 회원가입

1-1 회원가입 성공

curl

$ curl 'http://localhost:8080/users' -i -X POST \
    -H 'Content-Type: application/json;charset=UTF-8' \
    -d '{
  "email" : "1234test@gmail.com",
  "password" : "1234test@@",
  "nickName" : "형일",
  "address" : "서울",
  "phone" : "010-1234-1234"
}'

요청 필드

Path Type Description

email

String

이메일

password

String

비밀번호

nickName

String

프로필로 사용할 닉네임

address

String

주소

phone

String

휴대폰 번호

요청 예시

POST /users HTTP/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 149
Host: localhost:8080

{
  "email" : "1234test@gmail.com",
  "password" : "1234test@@",
  "nickName" : "형일",
  "address" : "서울",
  "phone" : "010-1234-1234"
}

응답 예시

HTTP/1.1 201 Created

1-2 중복된 이메일로 회원가입 실패

curl

$ curl 'http://localhost:8080/users' -i -X POST \
    -H 'Content-Type: application/json;charset=UTF-8' \
    -d '{
  "email" : "1234test@gmail.com",
  "password" : "1234test@@",
  "nickName" : "형일",
  "address" : "서울",
  "phone" : "010-1234-1234"
}'

요청 필드

Path Type Description

email

String

이메일

password

String

비밀번호

nickName

String

프로필로 사용할 닉네임

address

String

주소

phone

String

휴대폰 번호

요청 예시

POST /users HTTP/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 149
Host: localhost:8080

{
  "email" : "1234test@gmail.com",
  "password" : "1234test@@",
  "nickName" : "형일",
  "address" : "서울",
  "phone" : "010-1234-1234"
}

응답 예시

HTTP/1.1 409 Conflict
Content-Type: application/json;charset=UTF-8
Content-Length: 62

{
  "message" : "이미 존재하는 이메일 입니다."
}

2. 로그인

2-1 로그인 성공

curl

$ curl 'http://localhost:8080/users/login' -i -X POST \
    -H 'Content-Type: application/json;charset=UTF-8' \
    -d '{
  "email" : "test10@gmail.com",
  "password" : "1234test@@"
}'

요청 필드

Path Type Description

email

String

로그인을 위한 이메일

password

String

로그인을 위한 비밀번호

요청 예시

POST /users/login HTTP/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 66
Host: localhost:8080

{
  "email" : "test10@gmail.com",
  "password" : "1234test@@"
}

응답 예시

HTTP/1.1 200 OK

2-2 로그인 실패

curl

$ curl 'http://localhost:8080/users/login' -i -X POST \
    -H 'Content-Type: application/json;charset=UTF-8' \
    -d '{
  "email" : "test10@gmail.com",
  "password" : "1234test@@"
}'

요청 필드

Path Type Description

email

String

로그인을 위한 이메일

password

String

로그인을 위한 비밀번호

요청 예시

POST /users/login HTTP/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 66
Host: localhost:8080

{
  "email" : "test10@gmail.com",
  "password" : "1234test@@"
}

응답 예시

HTTP/1.1 401 Unauthorized
Content-Type: application/json;charset=UTF-8
Content-Length: 100

{
  "message" : "아이디가 존재하지 않거나 비밀번호가 일치하지 않습니다."
}

3. 로그아웃

3-1 로그아웃 성공

curl

$ curl 'http://localhost:8080/users/logout' -i -X POST \
    -H 'Content-Type: application/json;charset=UTF-8'

요청 예시

POST /users/logout HTTP/1.1
Content-Type: application/json;charset=UTF-8
Host: localhost:8080

응답 예시

HTTP/1.1 200 OK

4. 회원정보

4-1 회원정보 수정

curl

$ curl 'http://localhost:8080/users/my-info' -i -X PATCH \
    -H 'Content-Type: application/json;charset=UTF-8' \
    -F 'profileImage=@profileImage;type=image/png'

요청 예시

PATCH /users/my-info HTTP/1.1
Content-Type: application/json;charset=UTF-8; boundary=6o2knFse3p53ty9dmcQvWAIx1zInP11uCfbm
Host: localhost:8080

응답 예시

HTTP/1.1 201 Created

4-2 프로필 사진 삭제

curl

$ curl 'http://localhost:8080/users/profile-image' -i -X PUT \
    -H 'Content-Type: application/json;charset=UTF-8'

요청 예시

PUT /users/profile-image HTTP/1.1
Content-Type: application/json;charset=UTF-8
Host: localhost:8080

응답 예시

HTTP/1.1 200 OK

POSTS API

1. 게시물

1-1 게시물 작성

curl

$ curl 'http://localhost:8080/posts' -i -X POST \
    -H 'Content-Type: application/json;charset=UTF-8' \
    -d '{
  "title" : "제목",
  "content" : "내용"
}'

요청 필드

Path Type Description

title

String

게시물 제목

content

String

게시물 내용

요청 예시

POST /posts HTTP/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 51
Host: localhost:8080

{
  "title" : "제목",
  "content" : "내용"
}

응답 예시

HTTP/1.1 201 Created

1-2 게시물 수정

curl

$ curl 'http://localhost:8080/posts/1' -i -X PATCH \
    -H 'Content-Type: application/json;charset=UTF-8' \
    -d '{
  "title" : "제목",
  "content" : "내용"
}'

path-parameters ./posts/{id}

Parameter Description

id

수정할 게시글의 번호

요청 예시

PATCH /posts/1 HTTP/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 51
Host: localhost:8080

{
  "title" : "제목",
  "content" : "내용"
}

응답 예시

HTTP/1.1 201 Created

1-3 특정 회원 게시물 조회

curl

$ curl 'http://localhost:8080/posts?email=test@gmail.com&pageNo=0&pageSize=10' -i -X GET \
    -H 'Content-Type: application/json;charset=UTF-8'

요청 파라미터

Parameter Description

email

조회할 게시글을 작성한 사용자 이메일

pageNo

조회할 게시글의 페이지

pageSize

조회할 게시글의 페이지당 게시글 수

요청 예시

GET /posts?email=test@gmail.com&pageNo=0&pageSize=10 HTTP/1.1
Content-Type: application/json;charset=UTF-8
Host: localhost:8080

응답 필드

Path Type Description

nickName

String

조회한 게시글을 작성한 사용자의 닉네임

profileImagePath

Null

조회한 게시글을 작성한 사용자의 프로필 사진

posts.[].title

String

조회한 게시물의 제목

posts.[].content

String

조회한 게시물의 내용

응답 예시

HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Content-Length: 138

{
  "nickName" : "닉네임",
  "profileImagePath" : null,
  "posts" : [ {
    "title" : "제목",
    "content" : "내용"
  } ]
}

1-4 전체 회원 게시물 조회

curl

$ curl 'http://localhost:8080/posts/users?pageNo=0&pageSize=10' -i -X GET \
    -H 'Content-Type: application/json;charset=UTF-8'

요청 파라미터

Parameter Description

pageNo

조회할 게시글의 페이지

pageSize

조회할 게시글의 페이지당 게시글 수

요청 예시

GET /posts/users?pageNo=0&pageSize=10 HTTP/1.1
Content-Type: application/json;charset=UTF-8
Host: localhost:8080

응답 필드

Path Type Description

[].title

String

조회한 게시물의 제목

[].content

String

조회한 게시물의 내용

응답 예시

HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Content-Length: 55

[ {
  "title" : "제목",
  "content" : "내용"
} ]

1-5 게시물 삭제

curl

$ curl 'http://localhost:8080/posts/1' -i -X DELETE \
    -H 'Content-Type: application/json;charset=UTF-8'

path-parameters

Table 1. /posts/{id}
Parameter Description

id

삭제할 게시물의 번호

요청 예시

DELETE /posts/1 HTTP/1.1
Content-Type: application/json;charset=UTF-8
Host: localhost:8080

응답 예시

HTTP/1.1 200 OK