@scalar/api-client
Version:
the open source API testing client
42 lines • 1.66 kB
TypeScript
import type { HarRequest } from '@scalar/snippetz';
type HarToFetchRequestProps = {
/** The HAR Request object to convert */
harRequest: HarRequest;
};
/**
* Converts a HAR (HTTP Archive) Request to a Fetch API Request object.
*
* This function is the reverse of fetchRequestToHar - it takes a HAR request
* and converts it into a standard JavaScript Fetch API Request object.
*
* The conversion handles:
* - Request method and URL reconstruction
* - Headers reconstruction from HAR headers array
* - Cookies conversion to Cookie header
* - Form data (params) conversion to FormData or URLSearchParams
* - Body decoding
* - Content-Type and other header restoration
* - Query parameters (already embedded in the URL)
*
* Use cases:
* - Replaying recorded HTTP requests
* - Creating mock requests from HAR files
* - Testing with fixtures
* - Request caching and restoration
* - Re-executing historical API calls
*
* Note: The Fetch API Request object does not support setting the HTTP version,
* so that information from the HAR is not preserved in the returned Request.
* Query parameters are expected to be already part of the URL in the HAR.
*
* @see https://w3c.github.io/web-performance/specs/HAR/Overview.html
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request
*
* @example
* const harRequest = { method: 'POST', url: 'https://api.example.com', ... }
* const request = harToFetchRequest({ harRequest })
* const response = await fetch(request)
*/
export declare const harToFetchRequest: ({ harRequest }: HarToFetchRequestProps) => Request;
export {};
//# sourceMappingURL=har-to-fetch-request.d.ts.map