Skip to content

API Design Standards

27.1. RESTful API Rules

27.1.1. URL Naming

  • Only lowercase letters and hyphens (-) must be used. Underscores (_) and camelCase must not be used.
  • Resource names must use plural forms.
  • URLs must not end with a trailing slash (/).
CategoryCorrect ExampleIncorrect Example
Plural/api/users/api/user
Hyphen/api/user-profiles/api/user_profiles
Lowercase/api/users/api/Users

27.1.2. HTTP Methods

MethodPurposeExampleResponse Code
GETRetrieve resourceGET /api/users200
POSTCreate resourcePOST /api/users201
PUTFull resource updatePUT /api/users/1200
PATCHPartial resource updatePATCH /api/users/1200
DELETEDelete resourceDELETE /api/users/1204

27.1.3. URL Hierarchy

Relationships between resources must be expressed through URL paths.

GET /api/users/{userId}/orders          # List orders for a specific user
GET /api/users/{userId}/orders/{orderId}  # Specific order for a specific user
  • Nesting is permitted up to 2 levels only.
  • If nesting beyond 3 levels is required, query parameters must be used.

27.2. Request/Response Format

27.2.1. Standard Response Structure

Single resource response:

json
{
  "id": 1,
  "name": "John Doe",
  "email": "user@tienipia.com",
  "createdAt": "2026-02-28T10:30:00"
}

27.2.2. List Response (Pagination)

json
{
  "content": [
    {
      "id": 1,
      "name": "John Doe",
      "email": "user@tienipia.com"
    }
  ],
  "page": 0,
  "size": 20,
  "totalElements": 150,
  "totalPages": 8
}

27.2.3. Pagination Parameters

ParameterDescriptionDefault
pagePage number (starts from 0)0
sizePage size20
sortSort criteriaDefault sort when unspecified
GET /api/users?page=0&size=20&sort=createdAt,desc

27.2.4. Date/Time Format

  • The ISO 8601 format must be used: 2026-02-28T10:30:00
  • When a timezone is required: 2026-02-28T10:30:00+09:00

27.3. Error Code System

27.3.1. HTTP Status Codes

CodeMeaningUsage Criteria
200OKSuccessful retrieval or update
201CreatedSuccessful resource creation
204No ContentSuccessful deletion
400Bad RequestInput validation failure
401UnauthorizedAuthentication required
403ForbiddenInsufficient permissions
404Not FoundResource does not exist
409ConflictResource conflict (e.g., duplicate)
500Internal Server ErrorInternal server error

27.3.2. Custom Error Codes

Custom error codes must be used in addition to HTTP status codes to differentiate specific errors.

{prefix}{sequence}
PrefixDomainExample
CCommonC001 (invalid input)
UUserU001 (user not found)
AAuthenticationA001 (token expired)
OOrderO001 (order not found)

27.3.3. Standard Error Response Format

json
{
  "code": "U001",
  "message": "User not found.",
  "timestamp": "2026-02-28T10:30:00"
}

For input validation errors, field-level details must be included.

json
{
  "code": "C001",
  "message": "Invalid input values.",
  "timestamp": "2026-02-28T10:30:00",
  "errors": [
    {
      "field": "email",
      "value": "invalid-email",
      "reason": "Invalid email format."
    }
  ]
}

27.4. API Documentation

27.4.1. SpringDoc Implementation

All API projects must implement SpringDoc (OpenAPI 3.0) to provide Swagger UI.

xml
<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
  <version>2.8.4</version>
</dependency>
yaml
# application.yml
springdoc:
  swagger-ui:
    path: /swagger-ui.html
  api-docs:
    path: /v3/api-docs

27.4.2. API Annotations

OpenAPI annotations must be applied to Controllers and DTOs.

java
@RestController
@RequestMapping("/api/users")
@Tag(name = "Users", description = "User management API")
public class UserController {

  @Operation(summary = "Get user", description = "Retrieves a user by ID.")
  @ApiResponses({
      @ApiResponse(responseCode = "200", description = "Successfully retrieved"),
      @ApiResponse(responseCode = "404", description = "User not found")
  })
  @GetMapping("/{id}")
  public ResponseEntity<UserResponse> getUser(@PathVariable Long id) {
    return ResponseEntity.ok(userService.findById(id));
  }
}

27.4.3. Documentation Principles

  • All public APIs must include the @Operation annotation.
  • Request/response DTOs must include field descriptions.
  • Swagger UI must be enabled only in development/staging environments and disabled in production.

TIENIPIA QUALIFIED STANDARD