harproxyserver
Advanced tools
Comparing version 0.0.12 to 0.0.13
{ | ||
"name": "harproxyserver", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "A simple proxy server that records and plays back HTTP requests and responses in HAR format.", | ||
@@ -5,0 +5,0 @@ "author": "Yaacov Zamir <kobi.zamir@gmail.com>", |
@@ -26,6 +26,2 @@ [](https://badge.fury.io/js/harproxyserver) | ||
## API | ||
harproxyserver / [Exports](doc/modules.md) | ||
## Standalone Executable | ||
@@ -53,10 +49,49 @@ | ||
# In Your Project | ||
## API | ||
Import the server and utility functions in your project: | ||
Import the server and utility functions in your TypeScript project: | ||
``` ts | ||
```ts | ||
import { findHarEntry, recordedHarMiddleware } from 'harproxyserver'; | ||
``` | ||
Example 1: Using findHarEntry to find a specific GET request in a HAR log: | ||
```ts | ||
const harLog = ... // retrieve HAR log | ||
const method = 'GET'; | ||
const pathname = '/api'; | ||
const entry = findHarEntry(harLog, method, pathname); | ||
if (entry) { | ||
console.log(`Found entry with ID ${entry.id}`); | ||
} else { | ||
console.log('Entry not found'); | ||
} | ||
``` | ||
Example 2: Using findHarEntry to find a POST request with specific query parameters: | ||
```ts | ||
const harLog = ... // retrieve HAR log | ||
const method = 'POST'; | ||
const baseUrl = 'https://example.com/api'; | ||
const queryParams = { q: 'search term', page: 1 }; | ||
const url = new URL(baseUrl); | ||
for (const [key, value] of Object.entries(queryParams)) { | ||
url.searchParams.set(key, value); | ||
} | ||
const pathnameWithParams = `${url.pathname}${url.search}; | ||
const entry = findHarEntry(harLog, method, pathnameWithParams); | ||
if (entry) { | ||
console.log(`Found entry with ID ${entry.id}`); | ||
} else { | ||
console.log('Entry not found'); | ||
} | ||
``` | ||
# Command-Line Options | ||
@@ -63,0 +98,0 @@ |
85520
111