Content-Type and the Accept Header
Why JSON responses advertise application/json.
Content-Type and the Accept Header is a free Flask Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Flask Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Headers Carry Meaning
A response is more than a body. HTTP headers describe that body, and two of them decide how JSON flows between client and server. 📨
What Content-Type Says
The Content-Type header announces the format of the body you are sending. For JSON replies its value is application/json.
Content-Type: application/jsonjsonify Sets It for You
You rarely set this header by hand. When you call jsonify, Flask attaches application/json automatically, so clients always parse correctly.
Why It Matters to Clients
A browser or library reads Content-Type to decide how to handle the body. Seeing application/json, it parses text into a usable object.
Wrong Type, Wrong Result
Return JSON text as plain text/html and clients may not parse it. The body looks right but the missing signal breaks automatic decoding.
What the Accept Header Says
The request can carry an Accept header that lists formats the client wants. It is a wish, telling your server which response type fits best.
Accept: application/jsonContent-Type vs Accept
Keep the pair straight: Content-Type describes the body in the current message, while Accept states what the client hopes to receive back.
Reading Accept in Flask
You can inspect the request to honor what the caller wants. The request.accept_mimetypes proxy reveals the formats listed in that header.
request.accept_mimetypes["application/json"]Content Negotiation
Serving the format a client asked for is called content negotiation. An API can return JSON or HTML for the same route based on Accept.
Request Bodies Have Types Too
Incoming requests also carry Content-Type. When a client sends application/json, Flask knows the body is JSON and request.get_json can parse it.
Trust the Defaults
For most JSON APIs, jsonify handling Content-Type is all you need. Reach for Accept only when one route must serve multiple formats.
Quick Check
Tell apart the two headers that shape JSON exchange.
Recap
You learned that Content-Type labels the body and Accept asks for a format, and that jsonify sets application/json so JSON clients just work. 🎉
Frequently asked questions
Is the “Content-Type and the Accept Header” lesson free?
Yes — the full text of “Content-Type and the Accept Header” is free to read here on the web, and the Flask Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Flask Academy course, upgrade to CoddyKit PRO.
What will I learn in “Content-Type and the Accept Header”?
Why JSON responses advertise application/json. You practise Flask Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Flask Academy?
No prior experience is required. Flask Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Content-Type and the Accept Header” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Flask Academy lesson?
Yes. Every Flask Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- jsonify a Dictionary
- Return Lists and Nested Data
- Set Status Codes on JSON Replies
- Content-Type and the Accept Header