Configuration
addFormat()
Signature
Section titled “Signature”addFormat() — returns void
Available in: controller, model, test, migrator, migration, tabledefinition
Category: Miscellaneous Functions
Description
Section titled “Description”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).
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
extension | string | yes | — | File extension to add. |
mimeType | string | yes | — | Matching MIME type to associate with the file extension. |
Examples
Section titled “Examples”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.