Skip to content

Configuration

addFormat()

addFormat() — returns void

Available in: controller, model, test, migrator, migration, tabledefinition Category: Miscellaneous Functions

Registers a new MIME type in your Wheels application for use with responding to multiple formats. This is helpful when your app needs to handle file types beyond the defaults provided by Wheels (e.g., serving JavaScript, PowerPoint, JSON, custom data formats).

NameTypeRequiredDefaultDescription
extensionstringyesFile extension to add.
mimeTypestringyesMatching MIME type to associate with the file extension.
1. Add a JavaScript format
addFormat(
    extension="js",
    mimeType="text/javascript"
);

Allows controllers to respond to .js requests with the correct MIME type.

2. Add PowerPoint formats
addFormat(extension="ppt", mimeType="application/vnd.ms-powerpoint");
addFormat(extension="pptx", mimeType="application/vnd.ms-powerpoint");

Enables Wheels to correctly serve legacy and modern PowerPoint files.

3. Add JSON format
addFormat(
    extension="json",
    mimeType="application/json"
);

Useful for APIs that need to respond with .json requests.

4. Add PDF format
addFormat(
    extension="pdf",
    mimeType="application/pdf"
);

Ensures .pdf responses are correctly labeled for browsers.

5. Add multiple custom data formats
addFormat(extension="csv", mimeType="text/csv");
addFormat(extension="yaml", mimeType="application/x-yaml");

Expands your app to handle CSV and YAML outputs.