formatBody

fun formatBody(body: Any?, contentType: ContentType = ContentType.Any): String(source)

Formats the HTTP body for display, applying syntax highlighting if color output is enabled.

Accepts any body type:

  • String bodies are highlighted using the string-based JSON/form highlighter.

  • JsonElement bodies are highlighted via the element tree highlighter (no intermediate string).

  • Typed objects with a JSON contentType are encoded to JsonElement first if a serializer is available, then highlighted via the element tree highlighter.

  • All other cases fall back to Any.toString.

Returns an empty string if body is null or blank.

Return

The formatted body string, or an empty string if the body is null or blank.

Parameters

body

The HTTP body to format.

contentType

The content type of the body, used for syntax highlighting.