LittleShoot Labs

JSON Example

JSONP Example

JQuery Example

Help - Google Group

powered by app-engine-patch

Powered by Google App Engine

LittleShoot Logo

MIME API from LittleShoot Labs

The REST MIME API from your friendly coders at LittleShoot Labs is absurdly simple: a REST API for getting the MIME type for a file name, returning responses as JSON.

To lookup a single MIME type or to test the output, enter a file name below:
The form above calls the MIME API from JavaScript. You can test the API calls from the command line using curl, for example:
curl "http://www.mimeapi.org/api/mime?file=test.txt"
In response, you'll get the following raw JSON with Content-Type "application/json":
{"mimeType": "text/plain", "fileName": "test.txt"}
You can also request a callback (JSONP).
curl "http://www.mimeapi.org/api/mime?file=test.txt&callback=callMeBackIMissYou"
In response, you'll get the following JavaScript with Content-Type "text/javascript":
callMeBackIMissYou({"mimeType": "text/plain", "fileName": "test.txt"});
Here's some sample code in JQuery that's very similar to the code this page uses in the form above:
$.getJSON("http://www.mimeapi.org/api/mime?callback=?", {file:"test.txt"}, function(data) { var fn = data.fileName; var mimeType = data.mimeType; } );

At LittleShoot Labs, we came across a need for this with browser-based uploads to Amazon S3. With S3, you need to set the Content-Type of the file in the initial upload request. In a browser form context, however, you only have this information once the user has selected a file, so you need to intercept the submit event, lookup up the MIME type, and add it as a hidden field to the form before carrying through with the upload. With the MIME API, you can just make a quick AJAX call to get the MIME type to use. There's a more detailed discussion of this issue here.

As we're known to do over here at LittleShoot, the MIME API runs on Django on Google App Engine using App Engine Patch, so it should be able to handle whatever traffic you throw at it.

If you're curious to learn more about LittleShoot, feel free to:

Now, you might be thinking "that's the most ridiculous API I've ever seen," and you'd be right. It's a small, tiny building block that's completely useless for the vast majority of cases where you should clearly make these calls locally using the APIs available in your language of choice.

There are, however, cases where this API makes more sense than a local call. The primary example is when you need to dynamically determine a MIME type in JavaScript for any reason. The alternative would be to download an entire JavaScript file that does it all, such as the one here. This is fine, but the file is over 40K+. You typically don't need to resolve MIME types that frequently, so forcing another 40K+ JavaScript file down the pipe is just overkill. That's when the MIME API makes sense -- you can just send ~500 bytes (with HTTP headers) up in the request and get ~500 bytes back to resolve the type.

If we're missing types you'd like us to add, just let us know on our Google Group