Unit 5: Client-Server Communication and Routing - Practice Quiz
1 Which HTTP method is commonly used to retrieve a resource from a REST API?
2
What does an HTTP status code of 404 indicate?
3
What does the browser's fetch() function return?
4 Which Axios method sends a request to retrieve data?
axios.put()
axios.post()
axios.delete()
axios.get()
5 What should a React application display while an API request is still in progress?
6 When should an empty-state message normally be displayed?
7 Which React Hook is commonly used to start data fetching after a component renders?
useEffect
useContext
useRef
useState
8 Which example represents client state?
9
Which server-data feature must usually be implemented manually when fetching with only useEffect?
10 Which React Query Hook is primarily used to fetch and manage server data?
useQuery
useMemo
useLayoutEffect
useReducer
11 What is a main benefit of caching server data?
12 What does background synchronization do in a server-state library?
13 What is the main purpose of client-side routing in a React application?
14 In React Router, which component is commonly placed near the root to enable browser-based routing?
StrictMode
SuspenseList
BrowserRouter
QueryClient
15 Which React Router component is commonly used for declarative navigation?
Link
Route
Outlet
Navigate
16
Given the route path /users/:id, what does :id represent?
17
In the URL /products?category=books, which part is the query parameter value?
books
category
products
/products
18 Which React Router component displays the matched child route inside a parent layout?
Navigate
Link
Routes
Outlet
19 What is the purpose of a protected route?
20 What is the main goal of route-based code splitting?
21
A React application needs to update the email address of an existing user at /api/users/42. Which HTTP method best represents this operation when the complete updated representation is sent?
/api/users/42
/api/users/42
/api/users/42
/api/users/42
22
An API successfully creates a new order after receiving a POST request. Which status code most appropriately communicates this result?
201 Created
204 No Content
200 OK
304 Not Modified
23
Which Fetch API pattern correctly treats an HTTP 404 response as an error that can be handled by catch?
response.statusText as the request promise
fetch again inside the finally block
response.json() before checking response.ok
response.ok and throw when it is false
24 Which statement correctly compares a successful JSON request using Fetch and Axios?
response.json()
response.json() after every request
response.json()
25 A product list request succeeds but returns an empty array. Which UI behavior best distinguishes this result from a failed request?
26 When a user changes a search filter while a previous request is still pending, which approach most effectively prevents stale results from replacing newer results?
27
Why is a data-fetching operation usually placed inside useEffect rather than executed directly in the component body?
28
A component fetches data for userId. Which dependency array is appropriate when the effect should run again whenever userId changes?
[fetch]
[userId]
[]
[setUserId]
29 Which piece of data is most clearly client state rather than server state?
30 Why can server state require different handling from a local modal's open or closed state?
31
What is a common limitation of using a separate useEffect for every server-data dependency in a larger application?
32
In React Query, why should a query key include a changing value such as userId?
33 A mutation successfully updates a product's price. What is a typical React Query action to ensure a product-list query does not remain stale?
34 A cached query is shown immediately while React Query fetches newer data in the background. What user experience does this provide?
35
What is the likely effect of increasing a React Query staleTime from zero to five minutes?
36 What is the main advantage of client-side routing in a React single-page application?
37
In a React Router configuration, which route pattern matches /settings but not /settings/profile when using nested route definitions?
settings and no child route
:settings
* only
settings/*
38 Which approach is generally preferred for navigation triggered by a button inside a React component?
window.location every time
window.history.back() regardless of the destination
39
A route is defined as /products/:productId. Which value should a component obtain from the route when the URL is /products/73?
products with value 73
73 with value productId
productId with value products
productId with value 73
40
For the URL /search?term=react&page=2, which statement correctly describes term and page?
# symbol
41
A client sends PUT /users/42 with a complete representation of a user. The request times out, so the client retries it. Which server behavior best preserves HTTP and REST semantics?
409 Conflict because every retry is unsafe
42 with the submitted representation again
PUT as a partial update and preserve omitted fields
42
An API successfully processes POST /orders but the response body is empty because the resource is being finalized asynchronously. Which response most accurately communicates that processing has begun and identifies the future resource?
204 No Content with a retry instruction
200 OK with an empty response body
202 Accepted with a Location header
201 Created with the order representation
43
A React component uses fetch to load data. The server responds with status 404 and a JSON error body. Which implementation correctly causes the request to enter the catch path for that HTTP failure while preserving the parsed server message?
response.status is outside the 2xx range
response.ok, parse the body, then throw an error containing it
response.statusText because it always contains the JSON message
response.json() and rely on fetch to reject automatically
44
An Axios interceptor refreshes an expired token and retries the original request. Which design prevents an infinite retry loop when the refresh endpoint also returns 401?
GET
45 A search page keeps displaying old results while a new query is pending. The new request fails, and the old results remain visible with an error message. Which state model best represents this situation?
loading=true, existing data, and a recorded error
loading=false, existing data, and no error because data exists
loading=true, data=null, and error=null
loading=false, data=[], and error=null
46 Which rendering rule most reliably distinguishes an initial load, a successful empty result, and a failed refetch with usable previous data?
data is falsy
data.length === 0
47
A component fetches /api/items/${category} inside useEffect. The user changes categories quickly, and the slower first response arrives after the second. Which approach prevents stale data from overwriting the current category?
48
A fetch effect depends on an object named filters, which is recreated on every render even when its values are unchanged. What is the most appropriate correction?
filters from the dependency array
49 Which classification is most accurate for a paginated list loaded from an API and a locally selected sort direction?
50
Why can a useEffect-based data-fetching implementation briefly show results for an old route after navigation, even when the dependency array includes the route ID?
51
A component uses useEffect to synchronize a server record, local edits, retries, cache reuse, and refetching after window focus. Which limitation of this approach is most significant?
52
In React Query, a component displays a project's details. The project ID changes from 1 to 2. Which query configuration correctly keeps the records distinct and enables independent caching?
queryKey: ['project'] and switch only the query function
queryKey: ['project', projectId] and read the ID from the query key
enabled: false and manually assign the returned project
53 After a successful mutation updates a user's profile, the dashboard still shows an old cached summary. Which React Query action is generally appropriate when the mutation response does not contain the complete dashboard data?
key only
staleTime to zero permanently
invalidateQueries for the dashboard query key
54
A query uses a five-minute staleTime. The cached data is four minutes old, and the user revisits the page. What should normally happen?
55 A list should remain visible while a new page is fetched, but the UI must indicate that the page transition is in progress. Which strategy best supports this behavior?
56
A single-page React application uses client-side routing. Clicking an internal navigation link works, but refreshing /reports/2025 returns a server 404. What is the fundamental missing configuration?
useEffect that redirects after every refresh
57
A route configuration defines /users/:id before /users/new, and navigating to /users/new renders the user-detail page with id = "new". What is the most direct correction?
/users/new with a query parameter
/users/new route before the dynamic route
id parameter from the dynamic route
58
A form submits a new record and then navigates to /records/17. The user presses Back and returns to the form, which should not resubmit. Which navigation behavior is usually appropriate after successful creation?
59
A route /products/:productId renders a product page. The component fetches product data in an effect with an empty dependency array. What bug occurs when navigation changes only productId while the component instance is reused?
60
A list URL is /items?tag=react&page=2. The user changes only the tag. Which update best preserves predictable browser navigation and avoids stale pagination semantics?
page to 1 in the URL
URLSearchParams object without navigation
tag while retaining page=2 unconditionally
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →