0
0
Rest APIprogramming~10 mins

404 Not Found in Rest API - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - 404 Not Found
Client sends HTTP request
Server receives request
Check if resource exists
Return resource
Client receives response
The client sends a request; the server checks if the resource exists. If not, it returns a 404 Not Found response.
Execution Sample
Rest API
GET /api/users/123 HTTP/1.1
Host: example.com

Response:
HTTP/1.1 404 Not Found
Content-Type: application/json

{"error":"User not found"}
A client requests a user that does not exist; the server responds with 404 Not Found and an error message.
Execution Table
StepActionResource Exists?Response StatusResponse Body
1Client sends GET /api/users/123UnknownWaitingNone
2Server checks resourceNoDeterminedNone
3Server sends responseNo404 Not Found{"error":"User not found"}
4Client receives responseNo404 Not Found{"error":"User not found"}
💡 Resource does not exist, so server returns 404 Not Found response.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
resource_existsUnknownUnknownNoNoNo
response_statusNoneWaitingDetermined404 Not Found404 Not Found
response_bodyNoneNoneNone{"error":"User not found"}{"error":"User not found"}
Key Moments - 2 Insights
Why does the server return 404 Not Found instead of the requested data?
Because the server checked and found that the requested resource does not exist, as shown in step 2 and 3 of the execution table.
Is 404 Not Found an error in the client request or server problem?
404 Not Found means the client requested something that isn't there; it's not a server error but a missing resource, as seen in the response status in step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the response status at step 3?
A200 OK
B404 Not Found
C500 Internal Server Error
D301 Moved Permanently
💡 Hint
Check the 'Response Status' column at step 3 in the execution table.
At which step does the server determine the resource does not exist?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
Look at the 'Resource Exists?' column in the execution table.
If the resource existed, how would the response status change in the table?
AIt would change to 200 OK
BIt would change to 500 Internal Server Error
CIt would stay 404 Not Found
DIt would be 301 Moved Permanently
💡 Hint
Think about what status code means success versus not found.
Concept Snapshot
404 Not Found:
- HTTP status code meaning resource not found
- Server checks if resource exists
- If missing, returns 404 with error message
- Client receives 404 and knows resource is missing
- Common in REST APIs for invalid URLs or IDs
Full Transcript
When a client sends a request to a server, the server checks if the requested resource exists. If it does not, the server responds with a 404 Not Found status code and an error message. This tells the client that the resource is missing, not that the server failed. The client can then handle this response appropriately, such as showing a 'not found' message to the user.