400

Bad Request

개요

400 Bad Request는 요청이 잘못되어 서버가 처리할 수 없음을 나타내는 범용 클라이언트 오류입니다. 구문이 깨진 본문, 잘못된 프레이밍, 기본 검증 실패 등 요청 자체에 문제가 있을 때 반환됩니다.

가장 흔한 원인은 깨진 JSON, 필수 파라미터 누락, Content-Type 불일치입니다. 서버가 문법 단계에서 요청을 이해하지 못했다는 뜻이므로, 인증(401)이나 권한(403) 문제와는 층위가 다릅니다.

언제 발생하나

요청 / 응답 예시

요청
POST /api/users HTTP/1.1
Host: api.example.com
Content-Type: application/json

{"name": "Ada", }
응답
HTTP/1.1 400 Bad Request
Content-Type: application/json

{"error":"Malformed JSON","detail":"Unexpected token '}' at position 15"}

코드로 보기

app.post('/api/users', (req, res) => {
  if (!req.body || typeof req.body.name !== 'string')
    return res.status(400).json({ error: 'name is required' });
  // ...
});
from flask import abort, request
@app.post('/api/users')
def create():
    if not request.is_json:
        abort(400, 'expected application/json')
    return {}, 201

흔한 원인

해결 방법

실무 참고

관련 상태코드

관련 헤더

스펙 근거