MIME Type Lookup API: The Complete Guide

Need to determine MIME types for file handling? This guide covers everything you need to know about looking up MIME types via API, including extension mapping, content types, and implementation examples.

What are MIME Types?

MIME (Multipurpose Internet Mail Extensions) types are standardized identifiers used to indicate the nature and format of a document or file. They're essential for proper file handling in web applications, email systems, and APIs.

A MIME type looks like: application/json or image/png

MIME Type Structure

MIME types consist of two parts separated by a slash:

  • Type: The general category (text, image, audio, video, application)
  • Subtype: The specific format (plain, html, png, mp4, json)

Examples: text/html, image/jpeg, application/pdf

Pro Tip: Always set the correct Content-Type header when serving files to ensure browsers handle them properly.

Using the MIME Type API

TinyFn provides endpoints to look up MIME types:

API Request - By Extension
GET https://api.tinyfn.io/v1/mime-type?extension=pdf
Headers: X-API-Key: your-api-key
Response
{
  "extension": "pdf",
  "mime_type": "application/pdf",
  "type": "application",
  "subtype": "pdf",
  "description": "Portable Document Format",
  "compressible": false,
  "charset": null
}

Parameters

Parameter Type Description
extension string File extension (without dot)
mime_type string MIME type to look up extension for
filename string Full filename to extract MIME type

Code Examples

JavaScript / Node.js

// Look up MIME type by extension
const response = await fetch(
  'https://api.tinyfn.io/v1/mime-type?extension=json',
  { headers: { 'X-API-Key': 'your-api-key' } }
);
const data = await response.json();
console.log(data.mime_type); // "application/json"

// Look up extension by MIME type
const response2 = await fetch(
  'https://api.tinyfn.io/v1/mime-type?mime_type=image/png',
  { headers: { 'X-API-Key': 'your-api-key' } }
);
const data2 = await response2.json();
console.log(data2.extensions); // ["png"]

Python

import requests

# Get MIME type for file extension
response = requests.get(
    'https://api.tinyfn.io/v1/mime-type',
    params={'extension': 'mp4'},
    headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
print(f"MIME type: {data['mime_type']}")  # video/mp4

# Get MIME type from filename
response = requests.get(
    'https://api.tinyfn.io/v1/mime-type',
    params={'filename': 'document.pdf'},
    headers={'X-API-Key': 'your-api-key'}
)
print(response.json()['mime_type'])  # application/pdf

cURL

curl "https://api.tinyfn.io/v1/mime-type?extension=css" \
  -H "X-API-Key: your-api-key"

Common MIME Types

Extension MIME Type Description
.htmltext/htmlHTML document
.csstext/cssCSS stylesheet
.jsapplication/javascriptJavaScript
.jsonapplication/jsonJSON data
.pngimage/pngPNG image
.jpgimage/jpegJPEG image
.pdfapplication/pdfPDF document
.mp4video/mp4MP4 video

Best Practices

  1. Always set Content-Type: Include proper MIME types in HTTP responses
  2. Validate uploads: Check MIME types when accepting file uploads
  3. Don't trust extensions alone: File extensions can be spoofed
  4. Use standard types: Stick to registered MIME types when possible

Try the MIME Type API

Get your free API key and start looking up MIME types in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key