Consider a REST API where /users/{userId}/posts/{postId} returns a specific post of a user. What is the output of the following request handler when called with /users/5/posts/10?
def get_post(user_id, post_id): return f"User {user_id} requested post {post_id}"
Look carefully at the order of parameters in the function and the URL.
The URL /users/5/posts/10 maps user_id=5 and post_id=10. The function returns a string with these values in order.
Which of the following URLs correctly represents a nested resource where comments belong to a specific post?
Think about the hierarchy: comments belong to posts, so posts come first in the URL.
Nested resources are structured from parent to child. So /posts/456/comments/123 means comment 123 of post 456.
Given the following Flask route definitions, which option correctly identifies the error?
@app.route('/users//posts/')
def get_post(user_id, post_id):
return f"User {user_id} post {post_id}"
@app.route('/users//posts')
def get_posts(user_id):
return f"Posts for user {user_id}"
@app.route('/posts/')
def get_post_global(post_id):
return f"Post {post_id} globally" Consider how Flask matches routes and if any overlap can cause confusion.
There is no error; all routes are correctly defined. Flask matches routes in the order defined, with more specific routes first. The global '/posts/
Which of the following Express.js route definitions correctly handles a nested resource for /users/:userId/posts/:postId?
Remember the order of parameters in Express route handlers and how to access URL parameters.
Option B correctly uses req and res in order and accesses req.params for URL parameters.
In a REST API, the endpoint /users/7/orders returns all orders for user 7. The database has the following data:
- User 7 has 3 orders: IDs 101, 102, 103
- User 8 has 2 orders: IDs 201, 202
If the API code filters orders by user ID correctly, how many items will the response contain when calling /users/7/orders?
Count only orders belonging to user 7.
The endpoint returns orders only for user 7, who has 3 orders.