Content-Type
ELI5 — The Vibe Check
Content-Type is a header that tells the receiver what format the data is in. 'I'm sending you JSON.' 'I'm sending you a PNG image.' 'I'm sending you HTML.' Without it, the receiver has to guess what to do with the blob of bytes it received.
Real Talk
Content-Type is an HTTP header that indicates the media type (MIME type) of the request or response body. It helps the client or server parse the body correctly. Common values: application/json, text/html, multipart/form-data, application/x-www-form-urlencoded, image/png.
Show Me The Code
// Setting Content-Type in requests
// JSON API
fetch('/api', {
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
// File upload
const form = new FormData();
form.append('file', fileInput.files[0]);
fetch('/upload', { method: 'POST', body: form });
// Browser auto-sets Content-Type: multipart/form-data
When You'll Hear This
"Set Content-Type to application/json when sending JSON." / "The API rejected the request because Content-Type was missing."
Related Terms
Header
Headers are the metadata attached to HTTP requests and responses — information about the information.
MIME Type (Multipurpose Internet Mail Extensions Type)
A MIME type is a standardized label for what type of content something is. 'text/html' means HTML. 'image/jpeg' means a JPEG image.
Payload
Payload is the actual data carried in a request or response — the valuable cargo.
Request
A request is what your browser (or app) sends to a server when it wants something. 'Give me the homepage.' 'Give me that image.
Response
A response is what the server sends back after receiving a request.