UNPKG

fluentrest-ts

Version:

A lightweight, fluent TypeScript API testing library inspired by Java's RestAssured. Built on top of Axios, JSONPath, and Joi for powerful request handling and response validation.

35 lines (34 loc) 1.84 kB
import { AxiosRequestConfig, AxiosResponse } from "axios"; export type LogLevel = "debug" | "info" | "none"; export declare function writeLogFile(label: string, data: any): void; /** * Logs a labeled data message to the console and optionally to a file. * Logging respects the current log level and configured verbosity. * @param label - Descriptive label for the log entry. * @param data - Any payload to log (object, string, etc). * @param logLevel - Current configured log level. * @param logToFile - Flag indicating whether to write logs to a file. * @param level - Log level required to execute the log (defaults to 'info'). */ export declare function log(label: string, data: any, logLevel: LogLevel, logToFile: boolean, level?: LogLevel): void; /** * Logs request details including method, URL, headers, params, and body. * Respects the log level (skips if below 'info'). */ export declare function logRequest(config: AxiosRequestConfig, logLevel: LogLevel, logToFile: boolean): void; /** * Logs the full HTTP response: status, headers, and body. * Skips logging unless log level is 'info' or 'debug'. */ export declare function logResponse(response: AxiosResponse, logLevel: LogLevel, logToFile: boolean): void; /** * Logs errors that occur during request execution or assertions. * This always logs if log level is 'error' or higher. * Optionally writes error details to file if `toFile` is enabled. */ export declare function logError(error: any, label: string, logLevel: LogLevel, logToFile: boolean, responseBody?: any, errorCode?: string): void; /** * Helper to format error messages consistently for throwing or logging. * Includes optional context like payload and custom error code. */ export declare function formatError(message: string, error: any, responseBody?: any, errorCode?: string): string;