Bird
Raised Fist0
Rest APIprogramming~20 mins

Problem Details (RFC 7807) format in Rest API - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
RFC 7807 Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this RFC 7807 JSON example?

Given this JSON response following RFC 7807, what is the value of the title field?

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/msgs/abc"
}
AYour current balance is 30, but that costs 50.
Bhttps://example.com/probs/out-of-credit
C/account/12345/msgs/abc
DYou do not have enough credit.
Attempts:
2 left
💡 Hint

Look for the title key in the JSON object.

🧠 Conceptual
intermediate
1:30remaining
Which field in RFC 7807 is used to uniquely identify the specific occurrence of the problem?

In the Problem Details JSON format, which field uniquely identifies the specific occurrence of the problem?

Ainstance
Btitle
Ctype
Dstatus
Attempts:
2 left
💡 Hint

It is a URI reference that identifies the specific occurrence.

Predict Output
advanced
2:00remaining
What HTTP status code is represented in this RFC 7807 response?

Given this JSON snippet, what is the HTTP status code indicated?

Rest API
{
  "type": "https://example.com/probs/invalid-input",
  "title": "Invalid input provided.",
  "status": 422,
  "detail": "The 'email' field must be a valid email address.",
  "instance": "/users/abc123"
}
A400
B422
C500
D404
Attempts:
2 left
💡 Hint

Check the status field in the JSON.

Predict Output
advanced
2:00remaining
What is the output of this Python code parsing an RFC 7807 response?

Consider this Python code that parses an RFC 7807 JSON response. What does it print?

Rest API
import json

response = '''{
  "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/msgs/abc"
}'''

problem = json.loads(response)
print(problem.get('detail'))
Ahttps://example.com/probs/out-of-credit
BYou do not have enough credit.
CYour current balance is 30, but that costs 50.
D/account/12345/msgs/abc
Attempts:
2 left
💡 Hint

Look at the key used in problem.get().

🧠 Conceptual
expert
2:30remaining
Which statement about the 'type' field in RFC 7807 is correct?

Choose the correct statement about the type field in the Problem Details (RFC 7807) format.

AIt is a URI that identifies the problem type and should always be dereferenceable to human-readable documentation.
BIt is a short human-readable summary of the problem type.
CIt is a URI reference that identifies the specific occurrence of the problem.
DIt is the HTTP status code associated with the problem.
Attempts:
2 left
💡 Hint

Think about the purpose of the type field as defined in RFC 7807.

Practice

(1/5)
1. What is the main purpose of the Problem Details (RFC 7807) format in REST APIs?
easy
A. To speed up API response times
B. To standardize error responses so clients can understand errors better
C. To encrypt API responses for security
D. To format successful data responses uniformly

Solution

  1. Step 1: Understand the role of Problem Details format

    The format is designed to provide a consistent way to report errors in APIs.
  2. Step 2: Identify the main benefit

    It helps clients understand and handle errors better by standardizing error responses.
  3. Final Answer:

    To standardize error responses so clients can understand errors better -> Option B
  4. Quick Check:

    Purpose = Standardize error responses [OK]
Hint: Remember: Problem Details = standardized error info [OK]
Common Mistakes:
  • Confusing error format with data encryption
  • Thinking it speeds up API responses
  • Assuming it formats successful responses
2. Which of the following is a REQUIRED field in the Problem Details JSON object according to RFC 7807?
easy
A. type
B. status
C. detail
D. instance

Solution

  1. Step 1: Recall required fields in RFC 7807

    The RFC requires the "type" field to identify the error type URI.
  2. Step 2: Check other fields

    Fields like "status", "detail", and "instance" are optional but recommended.
  3. Final Answer:

    type -> Option A
  4. Quick Check:

    Required field = type [OK]
Hint: Only 'type' is mandatory in Problem Details [OK]
Common Mistakes:
  • Assuming 'status' is required
  • Confusing 'detail' as mandatory
  • Thinking 'instance' is always needed
3. Given this Problem Details JSON response:
{"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/msgs/abc"}

What is the HTTP status code indicated?
medium
A. 403
B. 404
C. 200
D. 500

Solution

  1. Step 1: Locate the status field in JSON

    The JSON has "status": 403, which indicates the HTTP status code.
  2. Step 2: Understand the meaning of 403

    403 means Forbidden, matching the error about insufficient credit.
  3. Final Answer:

    403 -> Option A
  4. Quick Check:

    Status code = 403 [OK]
Hint: Look for 'status' field for HTTP code [OK]
Common Mistakes:
  • Confusing status with 'detail' content
  • Picking 200 as success code
  • Ignoring the numeric status field
4. You receive this Problem Details JSON:
{"title": "Invalid input", "status": 400, "detail": "Missing required field 'name'"}

What is missing that violates RFC 7807 requirements?
medium
A. The 'title' field should be a URL
B. The 'status' field should be a string
C. The 'detail' field should be omitted
D. The 'type' field is missing

Solution

  1. Step 1: Check required fields in the JSON

    The 'type' field is required by RFC 7807 but is missing here.
  2. Step 2: Validate other fields

    'status' is correctly a number, 'detail' and 'title' are valid types.
  3. Final Answer:

    The 'type' field is missing -> Option D
  4. Quick Check:

    Missing required field = type [OK]
Hint: Always include 'type' field in Problem Details [OK]
Common Mistakes:
  • Thinking 'status' must be string
  • Removing 'detail' field
  • Assuming 'title' must be URL
5. You want to create a Problem Details response for a rate limit error. Which JSON object correctly follows RFC 7807 and clearly informs the client about the error?
hard
A. {"type": "rate-limit", "title": "Error", "status": 429, "detail": "Limit reached"}
B. {"title": "Rate limit exceeded", "status": "429", "detail": "Too many requests", "instance": "/api/v1/resource"}
C. {"type": "https://example.com/probs/rate-limit", "title": "Rate limit exceeded", "status": 429, "detail": "You have sent too many requests in a short time.", "instance": "/api/v1/resource"}
D. {"type": "https://example.com/probs/rate-limit", "title": "Rate limit exceeded", "status": 200, "detail": "Too many requests"}

Solution

  1. Step 1: Check required fields and correct types

    {"type": "https://example.com/probs/rate-limit", "title": "Rate limit exceeded", "status": 429, "detail": "You have sent too many requests in a short time.", "instance": "/api/v1/resource"} includes 'type' as a URI, 'title', numeric 'status' 429, 'detail', and 'instance' fields correctly.
  2. Step 2: Validate status code and clarity

    Status 429 means Too Many Requests, matching the error. Other options have missing or wrong fields or wrong status codes.
  3. Final Answer:

    {"type": "https://example.com/probs/rate-limit", "title": "Rate limit exceeded", "status": 429, "detail": "You have sent too many requests in a short time.", "instance": "/api/v1/resource"} -> Option C
  4. Quick Check:

    Correct fields and status = {"type": "https://example.com/probs/rate-limit", "title": "Rate limit exceeded", "status": 429, "detail": "You have sent too many requests in a short time.", "instance": "/api/v1/resource"} [OK]
Hint: Use URI in 'type' and correct numeric 'status' [OK]
Common Mistakes:
  • Using string instead of number for status
  • Missing 'type' or using non-URI string
  • Wrong HTTP status code for error