API Fundamentals Course
API Fundamentals
/
Intermediate

Content Types (MIME Types)

Definition

A standard identifier (MIME type) sent in an HTTP Header that tells the receiving client exactly what kind of data format is contained within the request or response body.

Explain Like I'm New

If the server sends you a file with 1,000 random bytes, your computer has no idea if it is a text document, an MP3 audio file, or a JPEG photo. The `Content-Type` header is the server telling the browser: 'Hey, this is a picture of a cat, please draw an image on the screen.'

Real World Example

Uploading an avatar. The frontend sends the image file and sets `Content-Type: image/png`. The backend reads the header, realizes it's an image, and saves it to an AWS S3 bucket instead of trying to parse it as text.

Common Use Cases

  • •File uploads
  • •API data formatting
  • •Browser rendering

Terminal Output

bash / terminal
/* Common Content-Type Examples */ // 1. JSON Data (99% of API interactions) Content-Type: application/json // 2. File Uploads (Images, PDFs) Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4 // 3. Standard HTML Form Submission (URL Encoded) Content-Type: application/x-www-form-urlencoded // 4. Returning a Web Page to the Browser Content-Type: text/html; charset=UTF-8 // 5. Returning an Image Content-Type: image/jpeg

Interview Questions

basic

  • What is the standard `Content-Type` value for a REST API returning JSON data?

intermediate

  • What `Content-Type` is required when you are submitting an HTML form that includes a File Upload (like an image)?

Flash Cards

Question

Standard JSON Content-Type?

Click to reveal answer
Answer

`application/json`

Question

File upload Content-Type?

Click to reveal answer
Answer

`multipart/form-data`. This special format allows the browser to chop the massive file into chunks and send it alongside standard text inputs.