HttpFormatter

open class HttpFormatter(theme: ColorTheme = ColorTheme.LIGHT_ON_DARK, useColor: Boolean = isColorSupported())(source)

A utility class to format HTTP requests and responses into colorized strings for better readability.

This formatter applies syntax highlighting based on HTTP methods, headers, bodies, and status codes. It supports customizable color themes and enables or disables colorization depending on platform support.

Parameters

theme

The color theme to be applied for formatting.

useColor

Boolean flag indicating whether ANSI color codes should be used in the formatting output.

Constructors

Link copied to clipboard
constructor(theme: ColorTheme = ColorTheme.LIGHT_ON_DARK, useColor: Boolean = isColorSupported())

Types

Link copied to clipboard
data class ColorScheme(val path: AnsiColor, val headerName: AnsiColor, val headerValue: AnsiColor, val body: AnsiColor)

Functions

Link copied to clipboard
fun formatBody(body: String?, contentType: ContentType = ContentType.Any): String

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

Link copied to clipboard
fun header(k: String, values: List<String>): String

Formats an HTTP header line with colorized header name and values.

Link copied to clipboard
fun requestLine(method: HttpMethod, path: String): String

Formats an HTTP request line with the method and path, applying colorization based on the selected theme.

Link copied to clipboard
fun responseLine(httpVersion: String, status: HttpStatusCode): String