412

Precondition Failed

4xx Client Error The client has indicated preconditions that the server does not meet

Code Examples

Here are examples of how to test HTTP 412 responses in different programming languages:

Select options below to see how to use advanced features in your code:

Request:
curl https://free.mockerapi.com/412
Response Body:
{
  "success": false,
  "status": 412,
  "statusText": "Precondition Failed - The client has indicated preconditions that the server does not meet",
  "timestamp": "2025-10-08T10:30:45.123Z",
  "request": {
    "method": "GET",
    "url": "/412",
    "fullUrl": "https://free.mockerapi.com/412"
  }
}
Request:
fetch('https://free.mockerapi.com/412')
  .then(response => {
    console.log('Status:', response.status); // 412
    return response.json();
  })
  .then(data => {
    console.log('Response:', data);
  })
  .catch(error => {
    console.error('Error:', error);
  });
Response Body:
{
  "success": false,
  "status": 412,
  "statusText": "Precondition Failed - The client has indicated preconditions that the server does not meet",
  "timestamp": "2025-10-08T10:30:45.123Z",
  "request": {
    "method": "GET",
    "url": "/412",
    "fullUrl": "https://free.mockerapi.com/412"
  }
}
Request:
import requests

response = requests.get('https://free.mockerapi.com/412')

print(f'Status Code: {response.status_code}')  # 412
print(f'Response: {response.json()}')
Response Body:
{
  "success": false,
  "status": 412,
  "statusText": "Precondition Failed - The client has indicated preconditions that the server does not meet",
  "timestamp": "2025-10-08T10:30:45.123Z",
  "request": {
    "method": "GET",
    "url": "/412",
    "fullUrl": "https://free.mockerapi.com/412"
  }
}
Request:
Response Body:
{
  "success": false,
  "status": 412,
  "statusText": "Precondition Failed - The client has indicated preconditions that the server does not meet",
  "timestamp": "2025-10-08T10:30:45.123Z",
  "request": {
    "method": "GET",
    "url": "/412",
    "fullUrl": "https://free.mockerapi.com/412"
  }
}
Request:
require 'net/http'
require 'json'

uri = URI('https://free.mockerapi.com/412')
response = Net::HTTP.get_response(uri)

puts "Status Code: #{response.code}"  # 412
puts "Response: #{JSON.parse(response.body)}"
Response Body:
{
  "success": false,
  "status": 412,
  "statusText": "Precondition Failed - The client has indicated preconditions that the server does not meet",
  "timestamp": "2025-10-08T10:30:45.123Z",
  "request": {
    "method": "GET",
    "url": "/412",
    "fullUrl": "https://free.mockerapi.com/412"
  }
}
Request:
package main

import (
    "fmt"
    "io"
    "net/http"
)

func main() {
    resp, err := http.Get("https://free.mockerapi.com/412")
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    fmt.Printf("Status Code: %d\n", resp.StatusCode)  // 412

    body, err := io.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }

    fmt.Printf("Response: %s\n", body)
}
Response Body:
{
  "success": false,
  "status": 412,
  "statusText": "Precondition Failed - The client has indicated preconditions that the server does not meet",
  "timestamp": "2025-10-08T10:30:45.123Z",
  "request": {
    "method": "GET",
    "url": "/412",
    "fullUrl": "https://free.mockerapi.com/412"
  }
}
Request:
import java.net.http.*;
import java.net.URI;

public class HttpStatusTest {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://free.mockerapi.com/412"))
            .GET()
            .build();

        HttpResponse response = client.send(request,
            HttpResponse.BodyHandlers.ofString());

        System.out.println("Status Code: " + response.statusCode());  // 412
        System.out.println("Response: " + response.body());
    }
}
Response Body:
{
  "success": false,
  "status": 412,
  "statusText": "Precondition Failed - The client has indicated preconditions that the server does not meet",
  "timestamp": "2025-10-08T10:30:45.123Z",
  "request": {
    "method": "GET",
    "url": "/412",
    "fullUrl": "https://free.mockerapi.com/412"
  }
}
Request:
const https = require('https');

https.get('https://free.mockerapi.com/412', (res) => {
  console.log('Status Code:', res.statusCode);  // 412

  let data = '';

  res.on('data', (chunk) => {
    data += chunk;
  });

  res.on('end', () => {
    console.log('Response:', JSON.parse(data));
  });
}).on('error', (err) => {
  console.error('Error:', err.message);
});
Response Body:
{
  "success": false,
  "status": 412,
  "statusText": "Precondition Failed - The client has indicated preconditions that the server does not meet",
  "timestamp": "2025-10-08T10:30:45.123Z",
  "request": {
    "method": "GET",
    "url": "/412",
    "fullUrl": "https://free.mockerapi.com/412"
  }
}

What is HTTP 412 Precondition Failed?

HTTP 412 Precondition Failed indicates that the server cannot or will not process the request due to something that is perceived to be a client error. This could be malformed request syntax, invalid request message framing, or deceptive request routing.

The client should not repeat the request without modifications.

When Does This Happen?

A 412 Precondition Failed response is returned when:

  • The request has invalid syntax or malformed request parameters
  • Required parameters are missing from the request
  • The request body contains invalid JSON or XML
  • Query parameters have invalid values or formats
  • The request URL is malformed or contains invalid characters
  • Request headers contain invalid or conflicting values

Try It Live

Click the button below to make a live request and see the 412 Precondition Failed response

Common Use Cases

🔍 Input Validation Testing

Test how your application handles invalid input data and displays appropriate error messages to users.

🛡️ Error Handling

Ensure your application properly catches and handles bad request errors without crashing.

📝 Form Validation

Test form validation logic and ensure users receive clear feedback about invalid submissions.

🔄 API Testing

Verify that your API correctly validates request parameters and returns appropriate error responses.

🎨 UI/UX Development

Design and test error states in your user interface for invalid requests.

📚 Documentation

Provide examples of bad request scenarios in API documentation for developers.

Related Client Error Status Codes