Format Code
Standard · 1 creditFormat source code using the right formatter for the language — Biome for JavaScript, TypeScript, CSS, and JSON; gofmt for Go.
POST /api/format-code
Parameters
Section titled “Parameters”| Field | Type | Required | Default | Description |
|---|---|---|---|---|
language | string | Yes | — | javascript (or js), typescript (or ts), jsx, tsx, json, css, go |
code | string | No* | — | Source code to format (single-file mode) |
files | object | No* | — | Map of filename → source code (multi-file mode) |
fragment | boolean | No | false | Treat input as a code fragment rather than a complete file |
config.indent_width | integer | No | — | Indentation width in spaces |
config.semicolons | boolean | No | — | Include semicolons (JS/TS) |
config.use_tabs | boolean | No | — | Use tabs instead of spaces |
*Provide either code (single file) or files (multiple files), not both.
Response
Section titled “Response”| Field | Type | Description |
|---|---|---|
formatted | string | Formatted code (single-file mode) |
files | object | Map of filename → formatted code (multi-file mode) |
language_detected | string | Language used for formatting |
changes_made | boolean | Whether the code was modified |
Examples
Section titled “Examples”Single file TypeScript
Section titled “Single file TypeScript”curl -X POST https://morso.dev/api/format-code \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"language": "typescript", "code": "const x=1;const y=2;function add(a:number,b:number){return a+b}"}'{ "formatted": "const x = 1;\nconst y = 2;\nfunction add(a: number, b: number) {\n\treturn a + b;\n}\n", "language_detected": "typescript", "changes_made": true}Multi-file mode
Section titled “Multi-file mode”curl -X POST https://morso.dev/api/format-code \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"language": "typescript", "files": {"index.ts": "const x=1", "utils.ts": "export const add=(a:number,b:number)=>a+b"}}'{ "files": { "index.ts": "const x = 1;\n", "utils.ts": "export const add = (a: number, b: number) => a + b;\n" }, "language_detected": "typescript", "changes_made": true}Custom config
Section titled “Custom config”curl -X POST https://morso.dev/api/format-code \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"language": "javascript", "code": "const x = 1", "config": {"use_tabs": true, "semicolons": false}}'{ "formatted": "const x = 1\n", "language_detected": "javascript", "changes_made": true}