Divide total by per_page: 5 / 2 = 2.5, round up to 3 pages.
Final Answer:
3 -> Option D
Quick Check:
5 items with 2 per page = 3 pages [OK]
Hint: Divide total items by per_page and round up [OK]
Common Mistakes:
Using integer division without rounding up
Confusing current page with total pages
Ignoring total count and using data length
4. You have this error response from a REST API:
{
"error": "Invalid ID",
"code": 400
}
But your client expects error details under the key "message" instead of "error". How can you fix this to follow consistent error patterns?
medium
A. Change the API to return {"message": "Invalid ID", "code": 400}
B. Change the client to look for "error" key instead of "message"
C. Ignore the error and retry the request
D. Remove the "code" key from the response
Solution
Step 1: Identify the inconsistency
The API returns error details under "error" but client expects "message" key.
Step 2: Fix the API response to match client expectation
Change the API to use "message" key for error details to keep consistent error format.
Final Answer:
Change the API to return {"message": "Invalid ID", "code": 400} -> Option A
Quick Check:
Consistent error keys = Use "message" key in API response [OK]
Hint: Match error keys between API and client [OK]
Common Mistakes:
Ignoring client expectations
Retrying without fixing error format
Removing important error code info
5. You want to design a REST API that returns a list of users with optional filtering by age and supports pagination. Which advanced pattern combination best solves this real problem?
hard
A. Use POST method to send filters in the body and ignore pagination.
B. Use query parameters for filters and pagination, and return consistent error messages.
C. Return all users in one response without filters or pagination.
D. Send filters as headers and paginate by splitting responses manually.
Solution
Step 1: Identify best practices for filtering and pagination
Filters are commonly passed as query parameters; pagination also uses query parameters for page and size.
Use query parameters for filters and pagination, and return consistent error messages. -> Option B
Quick Check:
Filters + pagination via query params + consistent errors = Use query parameters for filters and pagination, and return consistent error messages. [OK]
Hint: Use query params for filters and pagination [OK]
Common Mistakes:
Ignoring pagination causing large responses
Using POST instead of GET for filtering
Sending filters in headers which is non-standard
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.