Skip to content

Content-Type

Easy — everyone uses thisNetworking

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."

Made with passive-aggressive love by manoga.digital. Powered by Claude.