PHPackages                             chr15k/http-command-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. chr15k/http-command-generator

ActiveLibrary[Testing &amp; Quality](/categories/testing)

chr15k/http-command-generator
=============================

Generate curl commands in PHP with a fluent API—ideal for API testing, debugging, and CLI tools.

0.2.0(10mo ago)28MITPHPPHP ^8.2CI passing

Since Jun 20Pushed 10mo agoCompare

[ Source](https://github.com/chr15k/http-command-generator)[ Packagist](https://packagist.org/packages/chr15k/http-command-generator)[ RSS](/packages/chr15k-http-command-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (13)Used By (0)

HTTP Command Generator
======================

[](#http-command-generator)

 [![GitHub Workflow Status (main)](https://camo.githubusercontent.com/899d034ec179069f7476a6490d3caf876dad0802f437ea9083190c1ec43beb5c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f63687231356b2f687474702d636f6d6d616e642d67656e657261746f722f6d61696e2e796d6c)](https://github.com/chr15k/http-command-generator/actions) [![Total Downloads](https://camo.githubusercontent.com/2a078396c52ec0cbd639424a8ea023fc4ec89c5a29511c1cd308e63f1ea2430a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63687231356b2f687474702d636f6d6d616e642d67656e657261746f72)](https://packagist.org/packages/chr15k/http-command-generator) [![Latest Version](https://camo.githubusercontent.com/4ac4fe0ee0659f93038233f7549ebc9ac8c4aa20ba102937079f7d829e0148a8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63687231356b2f687474702d636f6d6d616e642d67656e657261746f72)](https://packagist.org/packages/chr15k/http-command-generator) [![License](https://camo.githubusercontent.com/49c42416e592fd0bdcf2856c5be7c9c7baaa72f7ec6034be76ab0fc517a242d9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f63687231356b2f687474702d636f6d6d616e642d67656e657261746f72)](https://packagist.org/packages/chr15k/http-command-generator)

### 📦 Overview

[](#-overview)

http-command-generator is a fluent PHP library for building curl commands and other HTTP CLI requests programmatically.

Designed for developers who want to generate real, runnable HTTP requests—not just send them—this package is perfect for:

- 🧪 API testing and debugging
- 🖥️ CLI tool integrations
- 📋 Generating copy-pasteable commands for docs or logs

With a clear fluent API, you can dynamically build requests with full control over methods, headers, query parameters, payloads, and authentication.

### ✨ Features

[](#-features)

- ✅ Fluent builder for curl and wget commands
- ✅ Supports headers, query params, JSON bodies, and files
- ✅ Built-in auth integration
- ✅ Zero external dependencies

Note

CLI tools currently supported are [cURL](https://curl.se/) and [wget](https://www.gnu.org/software/wget/)

Installation
------------

[](#installation)

Requires [PHP 8.2+](https://www.php.net/releases/)

```
composer require chr15k/http-command-generator
```

Basic Usage
-----------

[](#basic-usage)

### Simple GET Request

[](#simple-get-request)

```
use Chr15k\HttpCommand\HttpCommand;

// Build a simple GET request with cURL
$curl = HttpCommand::get('https://api.example.com/users')
    ->toCurl();

// Output: curl --location --request GET 'https://api.example.com/users'

// Generate the same request with wget
$wget = HttpCommand::get('https://api.example.com/users')
    ->toWget();

// Output: wget --no-check-certificate --quiet --method GET --timeout=0 'https://api.example.com/users'
```

### POST Request with JSON Body

[](#post-request-with-json-body)

```
use Chr15k\HttpCommand\HttpCommand;

// Build a POST request with JSON data using cURL
$curl = HttpCommand::post('https://api.example.com/users')
    ->json([
        'name' => 'John Doe',
        'email' => 'john@example.com',
    ])
    ->toCurl();

// Output: curl --location --request POST 'https://api.example.com/users' \
//  --header "Content-Type: application/json" \
//  --data '{"name":"John Doe","email":"john@example.com"}'

// Generate the same POST request using wget
$wget = HttpCommand::post('https://api.example.com/users')
    ->json([
        'name' => 'John Doe',
        'email' => 'john@example.com',
    ])
    ->toWget();

// Output: wget --no-check-certificate --quiet --method POST --timeout=0 \
//  --header 'Content-Type: application/json' \
//  --body-data '{"name":"John Doe","email":"john@example.com"}' \
//  'https://api.example.com/users'
```

### Authentication Examples

[](#authentication-examples)

#### Bearer Token Authentication

[](#bearer-token-authentication)

```
use Chr15k\HttpCommand\HttpCommand;

// Using a Bearer Token with cURL
$curl = HttpCommand::get('https://api.example.com/protected-resource')
    ->auth()->bearer('your-access-token')
    ->toCurl();

// Output: curl --location --request GET 'https://api.example.com/protected-resource' \
//  --header "Authorization: Bearer your-access-token"

// Using a Bearer Token with wget
$wget = HttpCommand::get('https://api.example.com/protected-resource')
    ->auth()->bearer('your-access-token')
    ->toWget();

// Output: wget --no-check-certificate --quiet --method GET --timeout=0 \
//  --header "Authorization: Bearer your-access-token" \
//  'https://api.example.com/protected-resource'
```

#### Basic Authentication

[](#basic-authentication)

```
use Chr15k\HttpCommand\HttpCommand;

// Using Basic Auth with cURL
$curl = HttpCommand::get('https://api.example.com/protected-resource')
    ->auth()->basic('username', 'password')
    ->toCurl();

// Output: curl --location --request GET 'https://api.example.com/protected-resource' \
//  --header "Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ="

// Using Basic Auth with wget
$wget = HttpCommand::get('https://api.example.com/protected-resource')
    ->auth()->basic('username', 'password')
    ->toWget();

// Output: wget --no-check-certificate --quiet --method GET --timeout=0 \
//  --header "Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=" \
//  'https://api.example.com/protected-resource'
```

#### API Key Authentication

[](#api-key-authentication)

```
use Chr15k\HttpCommand\HttpCommand;

// Using an API Key in header with cURL
$curl = HttpCommand::get('https://api.example.com/data')
    ->auth()->apiKey('X-API-Key', 'your-api-key')
    ->toCurl();

// Output: curl --location --request GET 'https://api.example.com/data' \
//  --header "X-API-Key: your-api-key"

// Using an API Key in query string with both generators
$curl = HttpCommand::get('https://api.example.com/data')
    ->auth()->apiKey('api_key', 'your-api-key', true)
    ->toCurl();

$wget = HttpCommand::get('https://api.example.com/data')
    ->auth()->apiKey('api_key', 'your-api-key', true)
    ->toWget();

// Output: curl --location --request GET 'https://api.example.com/data?api_key=your-api-key'
// Output: wget --no-check-certificate --quiet --method GET --timeout=0 'https://api.example.com/data?api_key=your-api-key'
```

#### Digest Authentication

[](#digest-authentication)

```
use Chr15k\HttpCommand\HttpCommand;
use Chr15k\AuthGenerator\Enums\DigestAlgorithm;

// Basic Digest Auth
$curl = HttpCommand::get('https://api.example.com/protected-resource')
    ->auth()->digest('username', 'password')
    ->toCurl();

// Output: curl --location --request GET 'https://api.example.com/protected-resource' \
//  --header 'Authorization: Digest username="username", realm="", nonce="", uri="", algorithm="MD5", response="..."'

// Advanced Digest Auth with all parameters
$curl = HttpCommand::get('https://api.example.com/protected-resource')
    ->auth()->digest(
        username: 'username',
        password: 'password',
        algorithm: DigestAlgorithm::MD5,
        realm: 'example.com',
        method: 'GET',
        uri: '/protected-resource',
        nonce: 'nonce_value',
        nc: '00000001',
        cnonce: 'cnonce_value',
        qop: 'auth'
    )
    ->toCurl();

// Using Digest Auth with wget
$wget = HttpCommand::get('https://api.example.com/protected-resource')
    ->auth()->digest(
        username: 'username',
        password: 'password',
        algorithm: DigestAlgorithm::MD5,
        realm: 'example_realm',
        method: 'GET',
        uri: '/protected-resource',
        nonce: 'nonce_value',
        nc: '00000001',
        cnonce: 'cnonce_value',
        qop: 'auth'
    )
    ->toWget();

// Output: wget --no-check-certificate --quiet --method GET --timeout=0 \
//  --header 'Authorization: Digest username="username", realm="example_realm", nonce="nonce_value", uri="/protected-resource", algorithm="MD5", qop=auth, nc=00000001, cnonce="cnonce_value", response="..."' \
//  'https://api.example.com/protected-resource'
```

### HTTP Methods

[](#http-methods)

The library supports all standard HTTP methods:

```
use Chr15k\HttpCommand\HttpCommand;

// Standard HTTP methods
$get = HttpCommand::get('https://api.example.com/users');           // GET
$post = HttpCommand::post('https://api.example.com/users');         // POST
$put = HttpCommand::put('https://api.example.com/users/1');         // PUT
$patch = HttpCommand::patch('https://api.example.com/users/1');     // PATCH
$delete = HttpCommand::delete('https://api.example.com/users/1');   // DELETE
$head = HttpCommand::head('https://api.example.com/users/1');       // HEAD
$options = HttpCommand::options('https://api.example.com/users');   // OPTIONS
```

### Query Parameters and Headers

[](#query-parameters-and-headers)

Both `query()` and `header()` methods are chainable, allowing you to build complex requests:

```
use Chr15k\HttpCommand\HttpCommand;

// Chaining multiple query parameters and headers
$curl = HttpCommand::get('https://api.example.com/search')
    ->header('Accept', 'application/json')
    ->header('User-Agent', 'MyApp/1.0')
    ->query('q', 'test')
    ->query('page', '1')
    ->query('limit', '10')
    ->auth()->bearer('your-token')
    ->toCurl();

// Output: curl --location --request GET 'https://api.example.com/search?q=test&page=1&limit=10' \
//  --header "Accept: application/json" \
//  --header "User-Agent: MyApp/1.0" \
//  --header "Authorization: Bearer your-token"
```

### Command Generator Methods

[](#command-generator-methods)

You can use either specific generator methods or the generic `to()` method:

```
// Using specific methods
$curl = HttpCommand::get('https://api.example.com')->toCurl();
$wget = HttpCommand::get('https://api.example.com')->toWget();

// Using the generic to() method
$curl = HttpCommand::get('https://api.example.com')->to('curl');
$wget = HttpCommand::get('https://api.example.com')->to('wget');
```

Advanced Usage
--------------

[](#advanced-usage)

### Working with Request Bodies

[](#working-with-request-bodies)

#### Form URL-encoded Data

[](#form-url-encoded-data)

```
use Chr15k\HttpCommand\HttpCommand;

// Form URL-encoded data with cURL
$curl = HttpCommand::post('https://api.example.com/form')
    ->form([
        'name' => 'John Doe',
        'email' => 'john@example.com',
    ])
    ->toCurl();

// Output: curl --location --request POST 'https://api.example.com/form' \
//  --header "Content-Type: application/x-www-form-urlencoded" \
//  --data-urlencode "name=John%20Doe" \
//  --data-urlencode "email=john%40example.com"

// Form URL-encoded data with wget
$wget = HttpCommand::post('https://api.example.com/form')
    ->form([
        'name' => 'John Doe',
        'email' => 'john@example.com',
    ])
    ->toWget();

// Output: wget --no-check-certificate --quiet --method POST --timeout=0 \
//  --header 'Content-Type: application/x-www-form-urlencoded' \
//  --body-data 'name=John%20Doe&email=john%40example.com' \
//  'https://api.example.com/form'
```

#### Multipart Form Data

[](#multipart-form-data)

```
use Chr15k\HttpCommand\HttpCommand;

// Multipart form data (useful for file uploads) with cURL
$curl = HttpCommand::post('https://api.example.com/upload')
    ->multipart([
        'file' => '@/path/to/file.jpg',
        'name' => 'Profile Photo',
    ])
    ->toCurl();

// Output: curl --location --request POST 'https://api.example.com/upload' \
//  --form "file=@/path/to/file.jpg" \
//  --form "name=Profile Photo"

// Note: wget doesn't support multipart form data natively like cURL does
// Instead, it converts to form data:
$wget = HttpCommand::post('https://api.example.com/upload')
    ->multipart([
        'name' => 'Profile Photo',
    ])
    ->toWget();

// Output: wget --no-check-certificate --quiet --method POST --timeout=0 \
//  --body-data 'name=Profile+Photo' \
//  'https://api.example.com/upload'
```

#### Binary Data

[](#binary-data)

```
use Chr15k\HttpCommand\HttpCommand;

// Send binary file content with cURL
$curl = HttpCommand::post('https://api.example.com/upload-binary')
    ->file('/path/to/file.bin')
    ->toCurl();

// Output: curl --location --request POST 'https://api.example.com/upload-binary' \
//  --data-binary '@/path/to/file.bin'

// Send binary file content with wget
$wget = HttpCommand::post('https://api.example.com/upload-binary')
    ->file('/path/to/file.bin')
    ->toWget();

// Output: wget --no-check-certificate --quiet --method POST --timeout=0 \
//  --body-file='/path/to/file.bin' \
//  'https://api.example.com/upload-binary'
```

### Custom Request Headers

[](#custom-request-headers)

The `header()` method is chainable, allowing you to add multiple headers easily:

```
use Chr15k\HttpCommand\HttpCommand;

// Chain multiple headers together
$curl = HttpCommand::get('https://api.example.com/data')
    ->header('Accept', 'application/json')
    ->header('Cache-Control', 'no-cache')
    ->header('User-Agent', 'MyApp/1.0')
    ->header('X-Custom-Header', 'custom-value')
    ->toCurl();

// Output: curl --location --request GET 'https://api.example.com/data' \
//  --header "Accept: application/json" \
//  --header "Cache-Control: no-cache" \
//  --header "User-Agent: MyApp/1.0" \
//  --header "X-Custom-Header: custom-value"

// Headers can be mixed with other methods in any order
$request = HttpCommand::post('https://api.example.com/users')
    ->header('Accept', 'application/json')
    ->auth()->bearer('token123')
    ->header('Content-Type', 'application/json')
    ->query('notify', 'true')
    ->header('X-Request-ID', 'req-456')
    ->json(['name' => 'John'])
    ->toCurl();
```

Command Generators
------------------

[](#command-generators)

HTTP Command Generator supports two command-line tools for making HTTP requests:

### cURL Generator

[](#curl-generator)

cURL is the most widely used command-line tool for HTTP requests and is the default generator:

```
$curl = HttpCommand::get('https://api.example.com/users')->toCurl();
```

### wget Generator

[](#wget-generator)

wget is an alternative command-line tool that's commonly available on Unix-like systems:

```
$wget = HttpCommand::get('https://api.example.com/users')->toWget();
```

Both generators support the same API and features, but have different output formats and capabilities. wget doesn't support all features that cURL does (like native multipart form data), but provides a good alternative for basic HTTP operations.

Line Break Formatting
---------------------

[](#line-break-formatting)

For better readability, especially when working with complex commands, you can enable line breaks in the generated commands using the `includeLineBreaks()` method:

```
use Chr15k\HttpCommand\HttpCommand;

// Default output (single line)
$command = HttpCommand::post('https://api.example.com/users')
    ->header('Authorization', 'Bearer token')
    ->header('Content-Type', 'application/json')
    ->json(['name' => 'John Doe', 'email' => 'john@example.com'])
    ->toCurl();

// Output: curl --location --request POST 'https://api.example.com/users' --header "Authorization: Bearer token" --header "Content-Type: application/json" --data '{"name":"John Doe","email":"john@example.com"}'

// With line breaks for better readability
$command = HttpCommand::post('https://api.example.com/users')
    ->header('Authorization', 'Bearer token')
    ->header('Content-Type', 'application/json')
    ->json(['name' => 'John Doe', 'email' => 'john@example.com'])
    ->includeLineBreaks()
    ->toCurl();

// Output: curl --location \
//   --request POST \
//   'https://api.example.com/users' \
//   --header "Authorization: Bearer token" \
//   --header "Content-Type: application/json" \
//   --data '{"name":"John Doe","email":"john@example.com"}'
```

The `includeLineBreaks()` method works with both cURL and wget generators and can be chained with any other builder methods.

Documentation
-------------

[](#documentation)

- [User Guide](https://github.com/chr15k/http-command-generator/blob/main/docs/USER_GUIDE.md) - Comprehensive guide with examples
- [API Cheat Sheet](https://github.com/chr15k/http-command-generator/blob/main/docs/API_CHEATSHEET.md) - Quick reference of all available methods

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

30

—

LowBetter than 65% of packages

Maintenance54

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

12

Last Release

316d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c817e814df42c78ac76505c9394a786946a0d9517b64984eca34b6f04010df95?d=identicon)[chr15k](/maintainers/chr15k)

---

Top Contributors

[![chr15k](https://avatars.githubusercontent.com/u/67823070?v=4)](https://github.com/chr15k "chr15k (77 commits)")

---

Tags

httpphptestingapiclicurlgeneratorcommandwget

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/chr15k-http-command-generator/health.svg)

```
[![Health](https://phpackages.com/badges/chr15k-http-command-generator/health.svg)](https://phpackages.com/packages/chr15k-http-command-generator)
```

###  Alternatives

[php-curl-class/php-curl-class

PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs.

3.3k9.5M351](/packages/php-curl-class-php-curl-class)[imbo/behat-api-extension

API extension for Behat

1082.5M9](/packages/imbo-behat-api-extension)[osteel/openapi-httpfoundation-testing

Validate HttpFoundation requests and responses against OpenAPI (3+) definitions

1201.9M6](/packages/osteel-openapi-httpfoundation-testing)[doppiogancio/mocked-client

A simple way to mock a client

2174.9k3](/packages/doppiogancio-mocked-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
