409 Conflict
Fault: Client
TL;DR
Request cannot be completed due to conflict with resource state.
The request conflicts with the current state of the server.
What This Error Means
The request conflicts with the current state of the server.
Request cannot be completed due to conflict with resource state.
Common Causes
- Version conflict
- Duplicate resource creation
- Concurrent modifications
- State mismatch
How to Fix It (For Visitors)
- Refresh the page and try again
- Resolve conflicts
How to Fix It (For Developers/Admins)
- Implement optimistic locking
- Use ETags for version control
- Handle concurrent updates
- Return conflict details in response
Code Examples
Here's how to return a 409 status code in various programming languages:
Python (Flask)
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/endpoint')
def endpoint():
return jsonify({"message": "Conflict"}), 409
Node.js (Express)
const express = require('express');
const app = express();
app.get('/endpoint', (req, res) => {
res.status(409).json({ message: 'Conflict' });
});
PHP
<?php
http_response_code(409);
header('Content-Type: application/json');
echo json_encode(['message' => 'Conflict']);
?>
Go
package main
import (
"encoding/json"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(409)
json.NewEncoder(w).Encode(map[string]string{
"message": "Conflict",
})
}
Java (Spring Boot)
@GetMapping("/endpoint")
public ResponseEntity<Map<String, String>> endpoint() {
Map<String, String> response = new HashMap<>();
response.put("message", "Conflict");
return ResponseEntity.status(409).body(response);
}
Ruby (Sinatra)
get '/endpoint' do
status 409
json message: 'Conflict'
end
Browser Compatibility
| Browser | Support | Notes |
|---|---|---|
| Chrome | ✓ Full Support | All versions |
| Firefox | ✓ Full Support | All versions |
| Safari | ✓ Full Support | All versions |
| Edge | ✓ Full Support | All versions |
Official Specification
This status code is defined in RFC 7231 Section 6.5.8.