Skip to content

Refactoring: restful한 API 설계 #6

Description

@Lee-JongSoo

현재 저희 api는 level1 수준입니다. 좀 더 restful한 api 설계를 위해 level2로 리펙토링 방향성을 제시합니다.

스크린샷 2022-07-31 오전 10 41 39

우선 level1에 맞지 않는 url 형태가 있습니다.

1. Path Variable에는 카멜케이스(camelCase)를 사용하자
Bad:

[GET] /orders/{order_id} 
[GET] /orders/{OrderId}

Good:
[GET] /orders/{orderId}

2. Collection에는 단수가 아닌 복수를 사용하자
Bad:

[GET] /user
[GET] /User

Good:
[GET] /users

3. Collection으로 시작해서 Identifier로 끝나자.
Bad:
[GET] /shops/{shopId}/products/{productId}/price
리소스 대신에 price라는 속성을 가리키기 때문에 좋지 않습니다.

Good:

[GET] /shops/{shopId}
[GET] /products/{productId}

이제 level2를 위한 리펙토링 방향성을 제시합니다.
HTTP method인 GET, POST, PUT, DELETE를 사용해 CRUD를 나타내고 메시지에 Status Code도 담겨 반환합니다.

Request

POST https://users
{
  "name": "nhn-commerce"
}

Response

HTTP/1.1 201 Created
Content-Type: application/json
{
  "result" {
    "id": "1",
    "name": "nhn-commerce"
  }
}

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions