티스토리 뷰

Project

product-api

ryumodern 2021. 10. 25. 19:20
상품

상품 단건 조회

Request

CURL

$ curl 'https://localhost:8443/api/products/1' -i -X GET \
    -H 'Accept: */*'

HTTPie

$ http GET 'https://localhost:8443/api/products/1' \
    'Accept:*/*'

Request HTTP Example

GET /api/products/1 HTTP/1.1
Accept: */*
Host: localhost:8443

Response

Response Fields

필드 타입 필수값 설명 제한

name

String

true

상품 이름

description

String

true

설명

productImage

String

사진

price

Number

true

가격

stock

Number

true

재고

createdDateTime

String

true

등록일

productCategory

String

true

분류

region

String

true

지역

memberResponse

Object

true

판매자

Response HTTP Example

HTTP/1.1 200 OK
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/hal+json
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Frame-Options: SAMEORIGIN
Content-Length: 999

{
  "name" : "panda",
  "description" : "nice bear",
  "productImage" : null,
  "memberResponse" : {
    "id" : 4,
    "email" : "panda@naver.com",
    "nickname" : "panda",
    "profileImage" : null,
    "phone" : "01012345678",
    "license" : null,
    "createdDateTime" : "2021-10-25T01:13:51.055049",
    "lastModifiedDateTime" : "2021-10-25T01:13:51.055049",
    "leaveDateTime" : null,
    "authority" : null,
    "address" : {
      "city" : "seoul",
      "street" : "yeonhui",
      "zipcode" : "01023"
    },
    "authProvider" : null,
    "status" : "ACTIVE"
  },
  "price" : 50000,
  "stock" : 15000,
  "createdDateTime" : "2021-10-25T01:13:51.057058",
  "productCategory" : "MEAT",
  "region" : "CHUNGCHEONGBUKDO",
  "_links" : {
    "self" : {
      "href" : "https://localhost:8443/api/products/1"
    },
    "modify-product" : {
      "href" : "https://localhost:8443/api/products/1"
    },
    "delete-product" : {
      "href" : "https://localhost:8443/api/products/1"
    }
  }
}

상품 다건 조회

Request

CURL

$ curl 'https://localhost:8443/api/products' -i -X GET \
    -H 'Accept: */*'

HTTPie

$ http GET 'https://localhost:8443/api/products' \
    'Accept:*/*'

Request HTTP Example

GET /api/products HTTP/1.1
Accept: */*
Host: localhost:8443

Response

Response Fields

필드 타입 필수값 설명 제한

_embedded.productResponseList[].name

String

true

상품 이름

_embedded.productResponseList[].memberResponse

Object

true

판매자

_embedded.productResponseList[].description

String

true

설명

_embedded.productResponseList[].productImage

String

사진

_embedded.productResponseList[].price

Number

true

가격

_embedded.productResponseList[].stock

Number

true

재고

_embedded.productResponseList[].createdDateTime

Varies

true

상품 등록일

_embedded.productResponseList[].productCategory

String

true

상품 분류

_embedded.productResponseList[].region

String

true

지역

Response HTTP Example

HTTP/1.1 200 OK
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/hal+json
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Frame-Options: SAMEORIGIN
Content-Length: 1107

{
  "_embedded" : {
    "productResponseList" : [ {
      "name" : "panda",
      "description" : "nice bear",
      "productImage" : null,
      "memberResponse" : {
        "id" : 5,
        "email" : "panda@naver.com",
        "nickname" : "panda",
        "profileImage" : null,
        "phone" : "01012345678",
        "license" : null,
        "createdDateTime" : "2021-10-25T01:13:51.096262",
        "lastModifiedDateTime" : "2021-10-25T01:13:51.096262",
        "leaveDateTime" : null,
        "authority" : null,
        "address" : {
          "city" : "seoul",
          "street" : "yeonhui",
          "zipcode" : "01023"
        },
        "authProvider" : null,
        "status" : "ACTIVE"
      },
      "price" : 50000,
      "stock" : 15000,
      "createdDateTime" : "2021-10-25T01:13:51.098958",
      "productCategory" : "MEAT",
      "region" : "CHUNGCHEONGBUKDO"
    } ]
  },
  "_links" : {
    "self" : {
      "href" : "https://localhost:8443/api/products?page=0&size=10"
    }
  },
  "page" : {
    "size" : 10,
    "totalElements" : 1,
    "totalPages" : 1,
    "number" : 0
  }
}

상품 추가

Request

CURL

$ curl 'https://localhost:8443/api/products' -i -X POST \
    -H 'Content-Type: application/json;charset=UTF-8' \
    -d '{
  "name" : "apple",
  "email" : "panda@naver.com",
  "description" : "delicious",
  "productImage" : "yaho",
  "price" : 3000,
  "stock" : 50000,
  "region" : "CHUNGCHEONGBUKDO",
  "productCategory" : "FRUIT"
}'

HTTPie

$ echo '{
  "name" : "apple",
  "email" : "panda@naver.com",
  "description" : "delicious",
  "productImage" : "yaho",
  "price" : 3000,
  "stock" : 50000,
  "region" : "CHUNGCHEONGBUKDO",
  "productCategory" : "FRUIT"
}' | http POST 'https://localhost:8443/api/products' \
    'Content-Type:application/json;charset=UTF-8'

Request Fields

필드 타입 필수값 설명 제한

name

String

true

상풍 이름

문자 형식 6-24자

email

String

true

판매자

이메일 형식 9-64자

description

String

true

상품 설명

자유 형식 빈 값 허용 안함

productImage

String

상품 이미지

문자 형식 최대 255자

price

Number

true

가격

숫자 형식

stock

Number

true

재고

숫자 형식

region

String

true

지역

Region class 참고

productCategory

String

true

판매자

ProductCategory class 참고

Request HTTP Example

POST /api/products HTTP/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 212
Host: localhost:8443

{
  "name" : "apple",
  "email" : "panda@naver.com",
  "description" : "delicious",
  "productImage" : "yaho",
  "price" : 3000,
  "stock" : 50000,
  "region" : "CHUNGCHEONGBUKDO",
  "productCategory" : "FRUIT"
}

Response

Response HTTP Example

HTTP/1.1 201 Created
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Frame-Options: SAMEORIGIN

상품 수정

Request

CURL

$ curl 'https://localhost:8443/api/products/1' -i -X PATCH \
    -H 'Content-Type: application/json;charset=UTF-8' \
    -d '{
  "name" : "bear",
  "description" : "good panda",
  "productImage" : null,
  "price" : null,
  "stock" : null,
  "region" : null,
  "productCategory" : null
}'

HTTPie

$ echo '{
  "name" : "bear",
  "description" : "good panda",
  "productImage" : null,
  "price" : null,
  "stock" : null,
  "region" : null,
  "productCategory" : null
}' | http PATCH 'https://localhost:8443/api/products/1' \
    'Content-Type:application/json;charset=UTF-8'

Request Fields

필드 타입 필수값 설명 제한

name

String

상풍 이름

문자 형식 6-24자

description

String

상품 설명

자유 형식 빈 값 허용 안함

productImage

String

상품 이미지

문자 형식 최대 255자

price

Number

가격

숫자 형식

stock

Number

재고

숫자 형식

region

String

지역

Region class 참고

productCategory

String

판매자

ProductCategory class 참고

Request HTTP Example

PATCH /api/products/1 HTTP/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 161
Host: localhost:8443

{
  "name" : "bear",
  "description" : "good panda",
  "productImage" : null,
  "price" : null,
  "stock" : null,
  "region" : null,
  "productCategory" : null
}

Response

Response HTTP Example

HTTP/1.1 201 Created
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/hal+json
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Frame-Options: SAMEORIGIN
Content-Length: 825

{
  "name" : "bear",
  "description" : "good panda",
  "productImage" : null,
  "memberResponse" : {
    "id" : 6,
    "email" : "panda@naver.com",
    "nickname" : "panda",
    "profileImage" : null,
    "phone" : "01012345678",
    "license" : null,
    "createdDateTime" : "2021-10-25T01:13:51.152869",
    "lastModifiedDateTime" : "2021-10-25T01:13:51.152869",
    "leaveDateTime" : null,
    "authority" : null,
    "address" : {
      "city" : "seoul",
      "street" : "yeonhui",
      "zipcode" : "01023"
    },
    "authProvider" : null,
    "status" : "ACTIVE"
  },
  "price" : 50000,
  "stock" : 15000,
  "createdDateTime" : "2021-10-25T01:13:51.155197",
  "productCategory" : "MEAT",
  "region" : "CHUNGCHEONGBUKDO",
  "_links" : {
    "self" : {
      "href" : "https://localhost:8443/api/products/1"
    }
  }
}

상품 단건 삭제

Request

CURL

$ curl 'https://localhost:8443/api/products/1' -i -X DELETE

HTTPie

$ http DELETE 'https://localhost:8443/api/products/1'

Request HTTP Example

DELETE /api/products/1 HTTP/1.1
Host: localhost:8443

Response

Response HTTP Example

HTTP/1.1 204 No Content
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Frame-Options: SAMEORIGIN

관리자 전용 상품 다건 조회

Request

CURL

$ curl 'https://localhost:8443/api/products/admin' -i -X GET \
    -H 'Content-Type: application/json;charset=UTF-8'

HTTPie

$ http GET 'https://localhost:8443/api/products/admin' \
    'Content-Type:application/json;charset=UTF-8'

Request HTTP Example

GET /api/products/admin HTTP/1.1
Content-Type: application/json;charset=UTF-8
Host: localhost:8443

Response

Response Fields

필드 타입 필수값 설명 제한

_embedded.productResponseList[].name

String

true

상풍 이름

_embedded.productResponseList[].description

String

true

상품 설명

_embedded.productResponseList[].price

Number

true

가격

_embedded.productResponseList[].stock

Number

true

재고

_embedded.productResponseList[].region

String

true

지역

_embedded.productResponseList[].productCategory

String

true

판매자

_embedded.productResponseList[].productImage

String

상품 이미지

_embedded.productResponseList[].memberResponse

Object

true

판매자

Response HTTP Example

HTTP/1.1 200 OK
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/hal+json
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Frame-Options: SAMEORIGIN
Content-Length: 1112

{
  "_embedded" : {
    "productResponseList" : [ {
      "name" : "panda",
      "description" : "nice bear",
      "productImage" : null,
      "memberResponse" : {
        "id" : 7,
        "email" : "panda@naver.com",
        "nickname" : "panda",
        "profileImage" : null,
        "phone" : "01012345678",
        "license" : null,
        "createdDateTime" : "2021-10-25T01:13:51.204335",
        "lastModifiedDateTime" : "2021-10-25T01:13:51.204335",
        "leaveDateTime" : null,
        "authority" : null,
        "address" : {
          "city" : "seoul",
          "street" : "yeonhui",
          "zipcode" : "01023"
        },
        "authProvider" : null,
        "status" : "ACTIVE"
      },
      "price" : 50000,
      "stock" : 15000,
      "createdDateTime" : "2021-10-25T01:13:51.20718",
      "productCategory" : "MEAT",
      "region" : "CHUNGCHEONGBUKDO"
    } ]
  },
  "_links" : {
    "self" : {
      "href" : "https://localhost:8443/api/products/admin?page=0&size=10"
    }
  },
  "page" : {
    "size" : 10,
    "totalElements" : 1,
    "totalPages" : 1,
    "number" : 0
  }
}

'Project' 카테고리의 다른 글

[notice-service] 게시글 REST API 구현하기  (0) 2021.11.20
board-api  (0) 2021.10.25
cart-api  (0) 2021.10.25
order-api  (0) 2021.10.25
member-api  (0) 2021.10.25
댓글
링크
글 보관함
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Total
Today
Yesterday