Bird
Raised Fist0
Rest APIprogramming~20 mins

Resource identifiers in URLs in Rest API - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Resource Identifier 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 URL parsing code?

Given the URL https://api.example.com/users/42/orders/7, what is the value of the resource identifier for the order?

Rest API
url = 'https://api.example.com/users/42/orders/7'
parts = url.split('/')
order_id = parts[-1]
print(order_id)
A42
Borders
Cusers
D7
Attempts:
2 left
💡 Hint

Look at the last part of the URL after splitting by '/'.

🧠 Conceptual
intermediate
1:30remaining
Which URL correctly identifies a single user resource?

Which of the following URLs correctly identifies a single user resource in a REST API?

Ahttps://api.example.com/users?id=123
Bhttps://api.example.com/users/123
Chttps://api.example.com/users/all
Dhttps://api.example.com/users/123/orders
Attempts:
2 left
💡 Hint

Single resource URLs usually have the resource type followed by its unique ID.

🔧 Debug
advanced
2:00remaining
Why does this URL cause a 404 error?

Given the REST API endpoint /products/{productId}, why does the URL /products/ cause a 404 error?

ABecause the productId is missing in the URL path
BBecause the HTTP method is incorrect
CBecause the server does not support trailing slashes
DBecause the query parameters are malformed
Attempts:
2 left
💡 Hint

Check if the URL includes the required resource identifier.

📝 Syntax
advanced
1:30remaining
Which URL pattern correctly uses resource identifiers for nested resources?

Which URL correctly represents accessing order 55 for user 10?

A/users/10/orders/55
B/orders/55/users/10
C/users/orders/10/55
D/orders/users/10/55
Attempts:
2 left
💡 Hint

Nested resources usually follow the pattern: parent resource, parent ID, child resource, child ID.

🚀 Application
expert
2:00remaining
How many resource identifiers are in this URL?

Count the number of resource identifiers in the URL https://api.example.com/companies/5/departments/3/employees/42.

A1
B2
C3
D4
Attempts:
2 left
💡 Hint

Resource identifiers are the numeric parts that identify specific resources.

Practice

(1/5)
1. What is the main purpose of resource identifiers in REST API URLs?
easy
A. To uniquely identify a specific resource
B. To specify the HTTP method used
C. To define the server address
D. To set the response format

Solution

  1. Step 1: Understand resource identifiers

    Resource identifiers are unique parts of a URL that point to a specific item or resource.
  2. Step 2: Identify their role in REST APIs

    They help the server know exactly which resource the client wants to access or modify.
  3. Final Answer:

    To uniquely identify a specific resource -> Option A
  4. Quick Check:

    Resource identifiers = unique resource ID [OK]
Hint: Resource IDs point to one item in the URL [OK]
Common Mistakes:
  • Confusing resource identifiers with HTTP methods
  • Thinking resource identifiers define server location
  • Mixing resource identifiers with response formats
2. Which of the following is the correct way to include a resource identifier for a user with ID 42 in a REST API URL?
easy
A. /users#42
B. /users?id=42
C. /users/42/details
D. /users/42

Solution

  1. Step 1: Identify the standard REST URL format

    Resource identifiers usually come directly after the resource name separated by a slash.
  2. Step 2: Check each option

    /users/42 uses "/users/42" which correctly places the ID after the resource name. /users?id=42 uses a query parameter, which is less common for resource identification. /users/42/details adds extra path which may refer to a sub-resource. /users#42 uses a fragment which is not for resource IDs.
  3. Final Answer:

    /users/42 -> Option D
  4. Quick Check:

    Resource ID follows resource name with slash [OK]
Hint: Resource ID follows resource name with a slash / [OK]
Common Mistakes:
  • Using query parameters instead of path segments
  • Adding extra path parts that change meaning
  • Using URL fragments (#) for resource IDs
3. Given the URL /products/123/reviews/456, which resource does the identifier 456 represent?
medium
A. Product with ID 456
B. Review with ID 456 for product 123
C. Product with ID 123
D. All reviews for product 456

Solution

  1. Step 1: Break down the URL path

    The URL has two resource names: "products" and "reviews" with IDs 123 and 456 respectively.
  2. Step 2: Understand the hierarchy

    "reviews/456" comes after "products/123", so 456 is the review ID related to product 123.
  3. Final Answer:

    Review with ID 456 for product 123 -> Option B
  4. Quick Check:

    Last ID is for last resource in URL [OK]
Hint: Last ID belongs to the last resource named [OK]
Common Mistakes:
  • Mixing IDs and thinking 456 is a product ID
  • Ignoring resource hierarchy in URL
  • Assuming IDs apply to all resources
4. Identify the error in this REST API URL for accessing order 789: /orders/ 789
medium
A. The resource identifier should be before the resource name
B. There should be no slash between resource name and ID
C. The ID should be part of the path, not separate
D. The URL is correct as is

Solution

  1. Step 1: Analyze the URL structure

    The URL shows /orders/ and then 789 separately, which suggests the ID is not part of the path.
  2. Step 2: Understand correct resource ID placement

    The ID should be directly after the resource name in the same path segment, like /orders/789.
  3. Final Answer:

    The ID should be part of the path, not separate -> Option C
  4. Quick Check:

    Resource ID must be in the path segment [OK]
Hint: Resource ID must be in the same path segment [OK]
Common Mistakes:
  • Placing ID outside the URL path
  • Removing the slash between resource and ID
  • Thinking resource ID comes before resource name
5. You want to design a REST API URL to access a comment with ID 555 on a post with ID 101. Which URL correctly uses resource identifiers to reflect this nested relationship?
hard
A. /posts/101/comments/555
B. /comments/555/posts/101
C. /posts/comments/555/101
D. /posts/555/comments/101

Solution

  1. Step 1: Understand resource hierarchy

    The comment belongs to a post, so the post resource should come first in the URL.
  2. Step 2: Check each URL option

    /posts/101/comments/555 correctly places the post ID first, then the comments resource with its ID. Other options mix the order or IDs incorrectly.
  3. Final Answer:

    /posts/101/comments/555 -> Option A
  4. Quick Check:

    Parent resource ID before child resource ID [OK]
Hint: Parent resource ID comes before child resource ID in URL [OK]
Common Mistakes:
  • Reversing parent and child resource order
  • Mixing IDs between resources
  • Placing IDs in wrong path segments
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard