Headers and representations
Content types and encodings
Use Content-Type, charset, and Content-Encoding to describe a message body accurately and avoid parsing or text-decoding errors.
7 minute lesson
Content-Type tells the recipient what the body contains:
Content-Type: application/json
Content-Type: text/html; charset=utf-8
Content-Type: image/webp
The media type determines which parser or renderer should handle the bytes. A JSON body sent as text/plain may still look readable, but clients cannot reliably treat it as JSON.
The charset parameter describes text encoding. UTF-8 is the normal choice for web text.
Content-Encoding is different. It describes a transformation applied for transport, such as gzip or br. The recipient decodes that layer and then interprets the result according to Content-Type.
In short: type says what it is; encoding says what happened to it on the way.
Lesson completed