REST Lens
← Back to All Rules
Rule 39

Content-Type Must Be Used

Category: Status Codes & Responses

Description

Responses with body content and request bodies must specify a Content-Type media type. Empty content definitions indicate missing type information.

What It Checks

This rule validates:

  • Response content definitions are not empty for 2XX, 4XX, and 5XX responses
  • Request body content definitions are not empty
  • Excludes 204 and 304 responses (which shouldn't have bodies)

Why It Matters

Specifying Content-Type is essential for:

  • Interoperability: Clients know how to parse responses
  • Documentation: Clear contract about data formats
  • Tooling Support: Code generators need content type information
  • HTTP Compliance: Content-Type is required for message bodies

Examples

Good

paths:
  /users:
    get:
      operationId: getUsers
      responses:
        '200':
          description: List of users
          content:
            application/json:
              schema:
                type: array
    post:
      operationId: createUser
      requestBody:
        content:
          application/json:
            schema:
              type: object
      responses:
        '201':
          description: User created
          content:
            application/json:
              schema:
                type: object

Bad

paths:
  /users:
    post:
      operationId: createUser
      requestBody:
        content: {}  # Empty content definition
      responses:
        '200':
          description: Success
          content: {}  # Empty content definition

Exceptions

  • 204 No Content responses (should not have a body)
  • 304 Not Modified responses (should not have a body)
  • Responses that legitimately have no body

Configuration

This rule has no configuration options. It is either enabled or disabled.

Related Rules

  • Rule 35: Code 204 Empty - No content responses
  • Rule 41: Consistent Media Types - Media type consistency
  • Rule 10: 415 Unsupported Media Type - Content type errors