← Back to Chapters

408 Request Timeout

⏱️ 408 Request Timeout

? Quick Overview

The 408 Request Timeout status code indicates that the server did not receive a complete request from the client within the time it was prepared to wait.

? Key Concepts

  • Client took too long to send the request
  • Server closed the idle connection
  • Occurs before request processing
  • Different from gateway timeout (504)

? Syntax / Theory

HTTP status code 408 belongs to the 4xx Client Error class. It is returned when the client initiates a request but fails to complete it within the server-defined timeout period.

? Code Example(s)

? View Code Example
// Example of an HTTP response with 408 status
HTTP/1.1 408 Request Timeout
Content-Type: text/html
Connection: close
? View Code Example
// Node.js example sending 408 response
res.status(408).send("Request Timeout");

? Live Output / Explanation

What Happens?

If a client does not send request headers or body data in time, the server terminates the connection and responds with 408 Request Timeout.

? Interactive / Visual Explanation

Imagine a server waiting for a request like a customer service desk. If no details are provided within a reasonable time, the request is dropped to free resources.

Server Patience Simulator

Click "Start Request" and try to click "Complete Data" before the timer runs out!

 
? View Code Example
// Pseudo timeline of a timeout scenario
Client connects → waits too long → server closes connection

? Use Cases

  • Slow internet connections
  • Unstable client-side applications
  • Large payload uploads without streaming
  • Idle API calls

✅ Tips & Best Practices

  • Set reasonable timeout values on servers
  • Use keep-alive connections carefully
  • Optimize client request generation
  • Handle retries gracefully on client side

? Try It Yourself

Simulate a delayed request using a network throttling tool or intentionally pause request sending to observe how servers respond with a timeout.