A 4xx response indicates that the consumer’s request contains an error or cannot be fulfilled as submitted. The class covers unparsable data, unsupported methods, missing properties, failed business checks, and insufficient rights. Its three-digit code also identifies responsibility even when the exact code is unfamiliar. section 4.5.1
Online Shopping API
Return 404 Not Found when /products/{product reference} identifies no product; do not use 204 No Content, which implies that the product exists without data. Return 400 Bad Request when product information is incorrect or incomplete. section 4.5.8
Choose a 4xx response by considering:
- Whether the consumer caused the failure rather than the provider; provider or implementation failures belong to the 5xx class. section 4.5.1
- The operation, HTTP method, and output; use registered, commonly understood codes and avoid unassigned custom statuses. section 4.5.2
Figure 4.12 An HTTP status has a numeric code and human-readable reason. The class system allows for easily identifying whether the code signifies a success or an error and who is at fault.
Use the status code and reason phrase together, then interpret the leading digit to identify success or responsibility. section 4.5.1
