]> Problem Details for HTTP APIs Akamai
mnot@mnot.net http://www.mnot.net/
UC Berkeley
dret@berkeley.edu http://dret.net/netdret/
status HTTP error problem API JSON XML This document defines a "problem detail" as a way to carry machine-readable details of errors in a HTTP response, to avoid the need to invent new error response formats for HTTP APIs. This draft should be discussed on the apps-discuss mailing list.
HTTP status codes are sometimes not sufficient to convey enough information about an error to be helpful. While humans behind Web browsers can be informed about the nature of the problem with an HTML response body, non-human consumers of so-called "HTTP APIs" are usually not. This specification defines simple JSON and XML document formats to suit this purpose. They are designed to be reused by HTTP APIs, which can identify distinct "problem types" specific to their needs. Thus, API clients can be informed of both the high-level error class (using the status code) and the finer-grained details of the problem (using one of these formats). For example, consider a response that indicates that the client's account doesn't have enough credit. The 403 Forbidden status code might be deemed most appropriate to use, as it will inform HTTP-generic software (such as client libraries, caches and proxies) of the general semantics of the response. However, that doesn't give the API client enough information about why the request was forbidden, the applicable account balance, or how to correct the problem. If these details are included in the response body in a machine-readable format, the client can treat it appropriately; for example, triggering a transfer of more credit into the account. This specification does this by identifying a specific type of problem (e.g., "out of credit") with a URI ; HTTP APIs can do this by nominating new URIs under their control, or by reusing existing ones. Additionally, problems can contain other information, such as a URI that identifies the specific occurrence of the problem (effectively giving an identifier to the concept "The time Joe didn't have enough credit last Thursday"), which may be useful for support or forensic purposes. The data model for problem details is a JSON object; when formatted as a JSON document, it uses the "application/problem+json" media type. defines how to express them in an equivalent XML format, which uses the "application/problem+xml" media type. Note that problem details are (naturally) not the only way to convey the details of a problem in HTTP; if the response is still a representation of a resource, for example, it's often preferable to accommodate describing the relevant details in that application's format. Likewise, in many situations, there is an appropriate HTTP status code that does not require extra detail to be conveyed. Instead, the aim of this specification is to define common error formats for those applications that need one, so that they aren't required to define their own, or worse, tempted to re-define the semantics of existing HTTP status codes. Even if an application chooses not to use it to convey errors, reviewing its design can help guide the design decisions faced when conveying errors in an existing format.
The canonical model for problem details is a JSON object. When serialised as a JSON document, that format is identified with the "application/problem+json" media type. For example, a HTTP response carrying JSON problem details:
A problem details object MAY have the following members: "type" (string) - An absolute URI that identifies the problem type. When dereferenced, it SHOULD provide human-readable documentation for the problem type (e.g., using HTML ). When this member is not present, its value is assumed to be "about:blank". "title" (string) - A short, human-readable summary of the problem type. It SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localisation. "status" (number) - The HTTP status code (, Section 6) generated by the origin server for this occurrence of the problem. "detail" (string) - An human readable explanation specific to this occurrence of the problem. "instance" (string) - An absolute URI that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced. Consumers MUST use the type string as the primary identifier for the problem type; the title string is advisory, and included only for users who are not aware of the semantics of the URI, and don't have the ability to discover them (e.g., offline log analysis). Consumers SHOULD NOT automatically dereference the type URI. The status member, if present, is only advisory; it conveys the HTTP status code used for the convenience of the consumer. Generators MUST use the same status code in the actual HTTP response, to assure that generic HTTP software that does not understand this format still behaves correctly. See for further caveats regarding its use. The detail member, if present, SHOULD focus on helping the client correct the problem, rather than giving debugging information. Consumers SHOULD NOT parse the detail member for information; extensions are more suitable and less error-prone ways to obtain such information.
Problem type definitions MAY extend the problem details object with additional members. For example, our "out of credit" problem above defines two such extensions, "balance" and "accounts" to convey additional, problem-specific information. Clients consuming problem details MUST ignore any such extensions that they don't recognise; this allows problem types to evolve and include additional information in the future.
When an HTTP API needs to define a response that indicates an error condition, it might be appropriate to do so by defining a new problem type. Before doing so, it's important to understand what they are good for, and what's better left to other mechanisms. Problem details are not a debugging tool for the underlying implementation; rather, they are a way to expose greater detail about the HTTP interface itself. New problem types need to carefully consider the Security Considerations (); in particular the risk of exposing attack vectors by exposing implementation internals through error messages. Likewise, truly generic problems – i.e., conditions that could potentially apply to any resource on the Web – are usually better expressed as plain status codes. For example, a "write access disallowed" problem is probably unnecessary, since a 403 Forbidden status code in response to a PUT request is self-explanatory. Finally, an application may have a more appropriate way to carry an error in a format that it already defines. Problem details are intended to avoid the necessity of establishing new "fault" or "error" document formats, not to replace existing domain-specific formats. That said, it is possible to add support for problem details to existing HTTP APIs using HTTP content negotiation (e.g., using the Accept request header to indicate a preference for this format). New problem type definitions MUST document: A type URI (typically, with the "http" scheme), A title that appropriately describes it (think short), and The HTTP status code for it to be used with. Problem types MAY specify the use of the Retry-After response header in appropriate circumstances. A problem's type URI SHOULD resolve to HTML documentation that explains how to resolve the problem. A problem type definition MAY specify additional members on the Problem Details object. For example, an extension might use typed links to another resource that can be used by machines to resolve the problem. If such additional members are defined, their names SHOULD start with a letter (ALPHA, as per ) and SHOULD consist of characters from ALPHA, DIGIT, and "_" (so that it can be serialized in formats other than JSON), and SHOULD be three characters or longer.
For example, if you are publishing an HTTP API to your online shopping cart, you might need to indicate that the user is out of credit (our example from above), and therefore cannot make the purchase. If you already have an application-specific format that can accommodate this information, it's probably best to do that. However, if you don't, you might consider using one of the problem details formats; JSON if your API is JSON-based, or XML if it uses that format. To do so, you might look for an already-defined type URI that suits your purposes. If one is available, you can reuse that URI. If one isn't available, you could mint and document a new type URI (which ought to be under your control and stable over time), an appropriate title and the HTTP status code that it will be used with, along with what it means and how it should be handled. In summary: an instance URI will always identify a specific occurrence of a problem. On the other hand, type URIs can be reused if an appropriate description of a problem type is already available someplace else, or they can be created for new problem types.
This specification reserves the use of one URI as a problem type: The "about:blank" URI , when used as a problem type, indicates that the problem has no additional semantics beyond that of the HTTP status code. When "about:blank" is used, the title SHOULD be the same as the recommended HTTP status phrase for that code (e.g., "Not Found" for 404, and so on), although it MAY be localized to suit client preferences (expressed with the Accept-Language request header). Please note that according to how the "type" member is defined (), the "about:blank" URI is the default value for that member. Consequently, any problem details object not carrying an explicit "type" member implicitly uses this URI.
This specification defines two new Internet media types :
Intended usage: COMMON Restrictions on usage: None. Author: Mark Nottingham Change controller: IESG ]]>
&rfc2119; &rfc7230; &rfc7231; &rfc3986; &rfc7159; &rfc5234; &xml; Information Technology --- Document Schema Definition Languages (DSDL) --- Part 2: Grammar-based Validation --- RELAX NG International Organization for Standardization &rfc7303; &rfc5988; &rfc6694; &rfc6838; &html; &rdfa;
Some HTTP-based APIs use XML as their primary format convention. Such APIs MAY express problem details using the format defined in this appendix. The OPTIONAL RELAX NG schema for the XML format is:
http://example.com/probs/out-of-credit You do not have enough credit. Your current balance is 30, but that costs 50. http://example.net/account/12345/msgs/abc 30 http://example.net/account/12345 http://example.net/account/67890 ]]>
In some situations, it can be advantageous to embed Problem Details in formats other than those described here. For example, an API that uses HTML might want to also use HTML for expressing its problem details. Problem details can be embedded in other formats by either encapsulating one of the existing serializations (JSON or XML) into that format, or by translating the model of a Problem Detail (as specified in ) into the format's conventions. For example, in HTML, a problem could be embedded by encapsulating JSON in a script tag:
{ "type": "http://example.com/probs/out-of-credit", "title": "You do not have enough credit.", "detail": "Your current balance is 30, but that costs 50.", "instance": "http://example.net/account/12345/msgs/abc", "balance": 30, "accounts": ["http://example.net/account/12345", "http://example.net/account/67890"] } }]]>
or by inventing a mapping into RDFa . This specification does not make specific recommendations regarding embedding Problem Details in other formats; the appropriate way to embed them depends both upon the format in use and application of that format.