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.

15 lines (14 loc) 544 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extract = extract; const jsonpath_plus_1 = require("jsonpath-plus"); /** * Extracts a value from the Axios response body using a JSONPath expression. * @param response - Axios response * @param path - JSONPath string expression * @returns The first match from the path, or undefined */ function extract(response, path) { const result = (0, jsonpath_plus_1.JSONPath)({ path, json: response.data }); return result.length ? result[0] : undefined; }