0
0
Rest APIprogramming~10 mins

Problem Details (RFC 7807) format in Rest API - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Problem Details (RFC 7807) format
Client sends request
Server detects error
Server creates Problem Details JSON
Server sends response with JSON
Client reads error details
Client handles error accordingly
The client sends a request; if the server finds an error, it sends back a JSON with problem details following RFC 7807; the client reads and handles the error.
Execution Sample
Rest API
{
  "type": "https://example.com/probs/out-of-credit",
  "title": "You do not have enough credit.",
  "status": 403,
  "detail": "Your current balance is 30, but that costs 50.",
  "instance": "/account/12345/transactions/abc"
}
This JSON shows a problem details response for a credit error with type, title, status, detail, and instance fields.
Execution Table
StepActionField CreatedValuePurpose
1Detect errortypehttps://example.com/probs/out-of-creditURI identifying error type
2Add short summarytitleYou do not have enough credit.Human-readable error title
3Add HTTP statusstatus403HTTP status code for error
4Add detailed messagedetailYour current balance is 30, but that costs 50.Detailed explanation of error
5Add instance URIinstance/account/12345/transactions/abcURI identifying specific occurrence
6Send responseJSON bodyFull JSON objectClient receives error details
7Client readsfieldsAll aboveClient can handle error based on info
8End--Process complete
💡 All problem details fields created and sent; client receives and processes error.
Variable Tracker
FieldStartAfter Step 1After Step 2After Step 3After Step 4After Step 5Final
typeundefinedhttps://example.com/probs/out-of-credithttps://example.com/probs/out-of-credithttps://example.com/probs/out-of-credithttps://example.com/probs/out-of-credithttps://example.com/probs/out-of-credithttps://example.com/probs/out-of-credit
titleundefinedundefinedYou do not have enough credit.You do not have enough credit.You do not have enough credit.You do not have enough credit.You do not have enough credit.
statusundefinedundefinedundefined403403403403
detailundefinedundefinedundefinedundefinedYour current balance is 30, but that costs 50.Your current balance is 30, but that costs 50.Your current balance is 30, but that costs 50.
instanceundefinedundefinedundefinedundefinedundefined/account/12345/transactions/abc/account/12345/transactions/abc
Key Moments - 3 Insights
Why do we use a URI in the 'type' field instead of just a short text?
The 'type' field uses a URI to uniquely identify the error type so clients can programmatically recognize and handle specific errors, as shown in execution_table step 1.
Is the 'status' field required and why is it useful?
Yes, 'status' is recommended to match the HTTP status code so clients can quickly understand the error category, as seen in execution_table step 3.
What is the purpose of the 'instance' field?
The 'instance' field gives a URI pointing to the specific occurrence of the problem, helping clients or support teams locate the exact error case, as added in execution_table step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 4, what is the value of the 'detail' field?
A403
BYou do not have enough credit.
CYour current balance is 30, but that costs 50.
Dhttps://example.com/probs/out-of-credit
💡 Hint
Check the 'detail' field value in execution_table row with step 4.
At which step is the HTTP status code added to the problem details JSON?
AStep 3
BStep 2
CStep 5
DStep 1
💡 Hint
Look for the 'status' field creation in execution_table.
If the 'instance' field was missing, which step would be skipped?
AStep 4
BStep 5
CStep 2
DStep 3
💡 Hint
Check which step adds the 'instance' field in execution_table.
Concept Snapshot
Problem Details (RFC 7807) format:
- JSON object with fields: type (URI), title (short text), status (HTTP code), detail (long text), instance (URI)
- Used to send standardized error info in REST APIs
- Helps clients understand and handle errors clearly
- 'type' URI uniquely identifies error kind
- 'status' matches HTTP response code
- 'instance' points to specific error occurrence
Full Transcript
This visual execution shows how a REST API server creates and sends a Problem Details JSON response following RFC 7807 when an error occurs. The server detects an error, then builds a JSON object step-by-step adding fields: 'type' as a URI to identify the error type, 'title' as a short human-readable summary, 'status' as the HTTP status code, 'detail' with a detailed explanation, and 'instance' as a URI pointing to the specific error occurrence. The client receives this JSON and can read these fields to understand and handle the error properly. Key points include the use of URIs for 'type' and 'instance' to uniquely identify errors and occurrences, and matching 'status' to the HTTP code. The execution table traces each step of building the JSON, and the variable tracker shows how each field is added. The quiz questions check understanding of field values and their creation steps.