Resource identifiers in URLs help us find and work with specific things on the internet, like a book or a user.
Resource identifiers in URLs in Rest API
/resource/{id}The {id} is a placeholder for the unique identifier of the resource.
Resource identifiers usually come after the main resource name in the URL.
/users/123/books/9780140449136/orders/789/items/456
This small web app uses resource identifiers in the URL to get user details by their ID.
For example, visiting /users/1 returns Alice's data.
from flask import Flask, jsonify app = Flask(__name__) # Sample data users = { '1': {'name': 'Alice', 'age': 30}, '2': {'name': 'Bob', 'age': 25} } @app.route('/users/<user_id>') def get_user(user_id): user = users.get(user_id) if user: return jsonify(user) else: return jsonify({'error': 'User not found'}), 404 if __name__ == '__main__': app.run(debug=True)
Resource identifiers should be unique within their resource type.
Use clear and simple IDs to make URLs easy to read and remember.
Nested resource identifiers help show relationships, like items inside orders.
Resource identifiers in URLs let you find and work with specific things online.
They usually come after the resource name and are unique IDs.
Using them makes your web addresses clear and organized.
Practice
Solution
Step 1: Understand resource identifiers
Resource identifiers are unique parts of a URL that point to a specific item or resource.Step 2: Identify their role in REST APIs
They help the server know exactly which resource the client wants to access or modify.Final Answer:
To uniquely identify a specific resource -> Option AQuick Check:
Resource identifiers = unique resource ID [OK]
- Confusing resource identifiers with HTTP methods
- Thinking resource identifiers define server location
- Mixing resource identifiers with response formats
Solution
Step 1: Identify the standard REST URL format
Resource identifiers usually come directly after the resource name separated by a slash.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.Final Answer:
/users/42 -> Option DQuick Check:
Resource ID follows resource name with slash [OK]
- Using query parameters instead of path segments
- Adding extra path parts that change meaning
- Using URL fragments (#) for resource IDs
/products/123/reviews/456, which resource does the identifier 456 represent?Solution
Step 1: Break down the URL path
The URL has two resource names: "products" and "reviews" with IDs 123 and 456 respectively.Step 2: Understand the hierarchy
"reviews/456" comes after "products/123", so 456 is the review ID related to product 123.Final Answer:
Review with ID 456 for product 123 -> Option BQuick Check:
Last ID is for last resource in URL [OK]
- Mixing IDs and thinking 456 is a product ID
- Ignoring resource hierarchy in URL
- Assuming IDs apply to all resources
/orders/ 789Solution
Step 1: Analyze the URL structure
The URL shows/orders/and then789separately, which suggests the ID is not part of the path.Step 2: Understand correct resource ID placement
The ID should be directly after the resource name in the same path segment, like/orders/789.Final Answer:
The ID should be part of the path, not separate -> Option CQuick Check:
Resource ID must be in the path segment [OK]
- Placing ID outside the URL path
- Removing the slash between resource and ID
- Thinking resource ID comes before resource name
Solution
Step 1: Understand resource hierarchy
The comment belongs to a post, so the post resource should come first in the URL.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.Final Answer:
/posts/101/comments/555 -> Option AQuick Check:
Parent resource ID before child resource ID [OK]
- Reversing parent and child resource order
- Mixing IDs between resources
- Placing IDs in wrong path segments
Ready to prove it?
Pass the test and this pattern moves unknown
