fetchify-curl
v1.0.0
Published
A TypeScript library for converting curl commands to fetch requests
Readme
fetchify-curl
A TypeScript library for converting curl commands to fetch requests. This library allows you to easily convert curl commands into fetch API calls that can be used in modern web applications.
Installation
npm install fetchify-curlUsage
import { curlToFetch } from 'fetchify-curl';
// Example curl command
const curlCommand = `curl -X POST https://api.example.com/data \
-H "Content-Type: application/json" \
-d '{"name": "John", "age": 30}'`;
// Convert and execute the curl command
try {
const response = await curlToFetch(curlCommand);
const data = await response.json();
console.log(data);
} catch (error) {
console.error('Error:', error);
}API
curlToFetch(curlCommand: string, clean: boolean = false): Promise<Response>
Converts a curl command to a fetch request and executes it.
curlCommand: The curl command string to convertclean: Whether to clean up headers (removes automatically added headers)- Returns: A Promise that resolves with the fetch Response
parseCurl(curlCommand: string, clean: boolean = false): CurlOptions
Parses a curl command string and returns the options object.
convertToFetchOptions(options: CurlOptions): FetchOptions
Converts curl options to fetch options.
Supported Curl Features
- HTTP methods (GET, POST, PUT, DELETE, etc.)
- Headers
- Request body (raw, form-urlencoded, multipart/form-data)
- Basic authentication
- Cookies
- URL parameters
- Compression
- Custom user agent
- Form data
Development
- Clone the repository
- Install dependencies:
npm install - Build the project:
npm run build
License
ISC
