UNPKG

api-response-utils

Version:

The api-response-utils package streamlines RESTful API data exchange by introducing a standardized data structure for HTTP response bodies. This structure simplifies client-side data handling, promoting consistency and readability in your API interactions

18 lines (17 loc) 684 B
import { IAPIResponse } from './types.js'; /** * Builds the response object that will be included in the HTTP body. Note that the error (if any) * will be processed and converted into a string regardless of the original type. * Moreover, a response with an error can also contain data. * @param data * @param error * @returns IAPIResponse */ declare const buildResponse: <T = undefined>(data?: T, error?: any) => IAPIResponse<T>; /** * Verifies if a given value is a valid API Response object. * @param response * @returns boolean */ declare const isResponse: <T>(response: unknown) => response is IAPIResponse<T>; export { type IAPIResponse, buildResponse, isResponse, };