Api Documentation

The formatting service is hosted as an azure function. Initial use will probably take some time (due to the warming of the azure function) but subsequent usages should be much quicker. To use the api you need to send a POST request to https://m-formatter.azurewebsites.net/api/format/v1 with content type application/json and the following body structure (typescript type declaration):
type RequestBody =
     code: string,
     config?: IConfig,   //optional, will use default config if not supplied
     resultType?: "html" | "text" //optional, default is "html". If set to "text", the resulting html will be converted to plaintext using html2plaintext.
A javascript usage example is provided in our example repository.
The config object is defined by
export interface IConfig
  debugPrint?: boolean;
  debugCursor?: boolean;
  debug?: boolean;
  //String that is used for indentation, default = "  "
  indentation?: string;
  //Length of the indentation string (is used for determining when the max line width is reached)
  indentationLength?: number;
  //String that is used to terminate a line, default = "<br/>"
  lineEnd?: string;
  //String that is used as a whitespace, default = "&nbsp;"
  ws?: string;
  //Maximum line width, default = 100. The formatter forces expression to break into several lines if the maximum line width would be reached. Please not some expressions cannot be broken into multiple lines such as very long identifiers and therefore the maximum line width can be exceeded in these cases. As of now there is no warning to give you info about that.
  lineWidth?: number;
  //Number of different bracket classes, default = 3. The formatter assigns bracket pairs the classes 'bracket' and 'bracket-{num}' where num = 1...{numBrackets}. You can then style your matching brackets with configurable depth.
  numBrackets?: number;
  //All text (code) is escaped into html format, default = true.
  escapeHtmlText?: boolean;
  //[DEPRECATED, use "alignPairedLetExpressionsByEqual" and "alignPairedReocrdExpressionsByEqual"] Align paired expressions by their equal sign, default = false.
  alignPairedExpressionsByEqual?: boolean;
  //Align paired expressions by their equal sign, default = false.
  alignPairedLetExpressionsByEqual?: AlignmentStrategy;
  //Align paired expressions by their equal sign, default = false.
  alignPairedRecordExpressionsByEqual?: AlignmentStrategy;
  //If null the formatter will put classes onto the resulting html but not styles (can be used for websites where you want to style the formatted html with css yourself). If non null the classes will be translated to inline styles on the html elements. See below for more information about the used classes.
  inlineCss?: string;
  //Toggles inline css usage;
  inlineCssToggle?: boolean;
  //Includes comments in the format results, default = true
  includeComments?: boolean;
  //Align line comments
  alignLineCommentsToPosition?: number;
  //Indent section members
  indentSectionMembers?: boolean;
  //Newline after CSV under LetExpression
  newLineCsvInLet?: boolean;
Available alignment strategy options are
export enum AlignmentStrategy
  //Never align
  never = "never",
  //Always align
  always = "always",
  //Only align when all expressions in the current scope are single line and won't exceed their line length when aligned by the equal sign.
  singleline = "singleline"
The css classes assigned by the formatter that can be used to customize the style either via the inlineCss config option or via css on your webpage are
  • comment
  • constant
    • keyword
    • identifier
      • method-call
    • operator
      • operator-dot
      • operator-keyword
    • bracket
    • bracket-{num}
    • type
  • literal
    • string
    • list
    • boolean
    • number
    • null
    • record
    • string


You will receive a response with Status 200 on success or Status 400 if an error occurred. In both cases the response body is a json object of type
type ResponseBody = {
  result: string, //HTML format result
  errors: FormatError[]
type FormatError = {
  kind: FormatErrorKind,
  innerError?: Error,   //the inner exception if there was one
  meta?: any,            //additional meta information,
  message: string
export type FormatErrorKind = 
  //an unknown error occurred. If this happens look at the innerError and possibly report the bug
  //parsing was unsuccessfull. As we use the official ms parser the problem is most likely within your code
  | "PARSER_ERROR"      
  //formatting was unsuccessfull. This is a strong indication of a bug, consider writing a bug report if this happens
  //the custom css that you provided is invalid
  | "CSS_ERROR"         
  //you provided an invalid config object
  //the formatter encountered an unknown node kind in the AST. Please note that section documents are currently not supported.
  //If this happens for code without sections then we are missing a node kind implementation. There are probabably some that we are missing but since our test bench does not include any of them it is hard for me to track them down. 
  //If you provide your query (or at least the portion of it that causes the error) it would help me out.

Terms of use

You are free to use the api as long as you give credit and (if you use the formatter for your website) link back to this site.