0
0
Rest APIprogramming~20 mins

Resource-based design thinking in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Resource Design Master
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 REST API response simulation?

Consider a REST API endpoint that returns a JSON object representing a resource. What will be the output when the following Python code simulates a GET request to this resource?

Rest API
import json

def get_resource():
    resource = {
        "id": 101,
        "type": "book",
        "attributes": {
            "title": "Learn REST",
            "author": "Jane Doe"
        },
        "links": {
            "self": "/api/books/101"
        }
    }
    return json.dumps(resource)

print(get_resource())
A{"resource_id": 101, "resource_type": "book", "details": {"title": "Learn REST", "author": "Jane Doe"}}
B{"id": 101, "type": "book", "title": "Learn REST", "author": "Jane Doe", "self": "/api/books/101"}
C{"id": 101, "type": "book", "attributes": {"title": "Learn REST", "author": "Jane Doe"}, "links": {"self": "/api/books/101"}}
D[{"id": 101, "type": "book", "attributes": {"title": "Learn REST", "author": "Jane Doe"}}]
Attempts:
2 left
💡 Hint

Look carefully at how the JSON object is structured with nested dictionaries and keys.

🧠 Conceptual
intermediate
1:30remaining
Which HTTP method is best suited for updating a resource partially?

In resource-based design thinking for REST APIs, which HTTP method should be used to update only some fields of an existing resource without replacing the entire resource?

APATCH
BDELETE
CPUT
DGET
Attempts:
2 left
💡 Hint

Think about the difference between replacing a resource and modifying parts of it.

🔧 Debug
advanced
2:00remaining
Identify the error in this REST API resource URL design

Which option shows an incorrect RESTful resource URL design for accessing a user's order?

A/users/123/orders/456/items
B/users/123/orders?id=456
C/users/123/orders/456
D/orders/456/users/123
Attempts:
2 left
💡 Hint

Consider the hierarchy and logical nesting of resources in RESTful URLs.

📝 Syntax
advanced
2:00remaining
Which JSON response correctly represents a collection of resources?

Given a REST API returning multiple book resources, which JSON response is correctly formatted to represent a collection?

A}]}"B kooB" :"eltit" ,2 :"di"{ ,}"A kooB" :"eltit" ,1 :"di"{[ :"skoob"{
B{"books": [{"id": 1, "title": "Book A"}, {"id": 2, "title": "Book B"}]}
C[{"id": 1, "title": "Book A"}, {"id": 2, "title": "Book B"}]
D{"book": [{"id": 1, "title": "Book A"}, {"id": 2, "title": "Book B"}]}
Attempts:
2 left
💡 Hint

Look for proper JSON syntax with arrays and objects.

🚀 Application
expert
1:30remaining
What is the correct status code for a successful resource creation in REST API?

When a new resource is successfully created using a POST request, which HTTP status code should the server return?

A201 Created
B200 OK
C204 No Content
D202 Accepted
Attempts:
2 left
💡 Hint

Think about the standard code that indicates a new resource was made.