0Pricing
Flask Academy · 강의

JSON 응답에 상태 코드 설정하기

JSON 본문에 201, 404 등의 상태 코드를 함께 지정합니다.

JSON 응답에 상태 코드 설정하기은(는) CoddyKit의 무료 Flask Academy 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Flask Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Flask Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Status Codes Tell the Story

Every HTTP response carries a status code that signals success or failure. Your JSON body explains the details, but the code sets the tone first. 🚦

The Default Is 200

When you return jsonify alone, Flask sends 200 OK. That is perfect for a successful read, but other actions deserve their own code.

Return a Tuple

To choose a code, return a tuple of the JSON response and the number. Flask reads the second element as the HTTP status to send.

return jsonify(message="created"), 201

201 for Created

When a request creates a new record, reply with 201 Created. It tells the client the resource now exists, which 200 alone would not convey.

return jsonify(id=new_id), 201

404 for Not Found

If the requested item does not exist, return a JSON body with 404. The client learns the resource is missing, not that the server broke.

return jsonify(error="user not found"), 404

400 for Bad Input

When a client sends invalid data, answer with 400 Bad Request. Pair it with a JSON message that explains exactly what went wrong.

return jsonify(error="name is required"), 400

The 2xx Family

Codes in the 2xx range mean success. 200 reads, 201 creates, and 204 signals success with no body to send back.

The 4xx Family

Codes in the 4xx range blame the client. 400 means bad input, 401 means unauthenticated, and 403 means forbidden.

The 5xx Family

Codes in the 5xx range blame the server. A 500 means your code raised an unhandled error while processing an otherwise valid request.

Adding Headers Too

You can extend the tuple to three parts: body, status, and a headers dict. That lets you attach extra metadata in one clean return.

return jsonify(ok=True), 201, {"X-Created": "now"}

Consistency Builds Trust

Pick the right code for every outcome and use it everywhere. Consistent status codes make your API predictable and a joy to integrate.

Quick Check

Match the action to the most fitting HTTP status code.

Recap

You learned to pair JSON bodies with the right status code by returning a tuple, using 201, 404, and 400 to make your API clear and honest. ✅

자주 묻는 질문

“JSON 응답에 상태 코드 설정하기” 강의는 무료인가요?

네 — “JSON 응답에 상태 코드 설정하기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Flask Academy 강의 전체를 잠금 해제할 수 있습니다. Flask Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

“JSON 응답에 상태 코드 설정하기”에서 뭘 배우나요?

JSON 본문에 201, 404 등의 상태 코드를 함께 지정합니다. 브라우저에서 직접 실행하는 실습 코드로 Flask Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Flask Academy을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Flask Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.

“JSON 응답에 상태 코드 설정하기” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Flask Academy 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Flask Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 딕셔너리를 jsonify하기
  2. 목록과 중첩 데이터 반환하기
  3. JSON 응답에 상태 코드 설정하기
  4. Content-Type과 Accept 헤더
← Flask Academy(으)로 돌아가기