PHPackages                             alexkart/curl-builder - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. alexkart/curl-builder

ActiveLibrary[HTTP &amp; Networking](/categories/http)

alexkart/curl-builder
=====================

PSR-7 compatible curl builder.

1.1.0(1y ago)19456.5k↑23%4[1 PRs](https://github.com/alexkart/curl-builder/pulls)2MITPHPPHP &gt;=7.3CI failing

Since Jul 25Pushed 6mo ago2 watchersCompare

[ Source](https://github.com/alexkart/curl-builder)[ Packagist](https://packagist.org/packages/alexkart/curl-builder)[ RSS](/packages/alexkart-curl-builder/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (5)Versions (13)Used By (2)

curl-builder [![build](https://github.com/alexkart/curl-builder/actions/workflows/php.yml/badge.svg)](https://github.com/alexkart/curl-builder/actions/workflows/php.yml) [![Code Coverage](https://camo.githubusercontent.com/529fd9487576ce62220c95b71dfef3a07d807ef89aec973bd10a23b86de1971e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f616c65786b6172742f6375726c2d6275696c6465722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/alexkart/curl-builder/?branch=master)
===================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#curl-builder--)

curl-builder is a curl command generator which can generate curl commands automatically from PSR-7 server requests and manually by specifying options and URL.

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

[](#installation)

```
composer require alexkart/curl-builder
```

Examples
--------

[](#examples)

### Generating curl command from PSR-7 request

[](#generating-curl-command-from-psr-7-request)

```
$request = new Request('POST', 'http://example.com', [
    'Connection' => ['keep-alive'],
    'Accept' => [
        'text/html',
        'application/xhtml+xml',
    ],
], 'data');
$command = new Command();
$command->setRequest($request);
$curl = $command->build();
// curl -H 'Connection: keep-alive' -H 'Accept: text/html, application/xhtml+xml' -d 'data' http://example.com
```

### Constructing curl command manually

[](#constructing-curl-command-manually)

```
$command = new Command();
$command->setUrl('http://example.com');
$command->addOption('-v');
$command->addOption('-H', 'Connection: keep-alive');
$command->addOption('-H', 'Cache-Control: max-age=0');
$curl = $command->build();
// curl -v -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' http://example.com
```

### Adding options

[](#adding-options)

Options can be added to the command one by one with `addOption()`

```
$command->addOption('-L');
$command->addOption('-v');
$command->addOption('-H', 'Connection: keep-alive');
// curl -L -v -H 'Connection: keep-alive' ...
```

or add several of them at once with `addOptions()`

```
$command->addOption('-v');
$command->addOptions([
    '-L',
    '-d' => 'test'
]);
// curl -v -L -d 'test' ...
```

`setOptions()` can be used to override previously set options

```
$command->setOptions(['-L', '-v']);
// curl -L -v ...
```

`addOptions()` and `setOptions()` formats:

```
// options without arguments
// the following lines will generate the same command
$command->setOptions(['-L' => [null], '-v' => [null]]);
$command->setOptions(['-L' => null, '-v' => null]);
$command->setOptions(['-L', '-v']);
// curl -L -v ...

// options with arguments
$command->setOptions(['-H' => 'test']);
// curl -H 'test' ...
$command->setOptions(['-H' => ['test1', 'test2']]);
// curl -H 'test1' -H 'test2' ...
```

### Specifying command template

[](#specifying-command-template)

Default template for the command is `{name}{options}{url}`. But you can change it with `setTemplate()` method

```
$command = new Command();
$command->setUrl('http://example.com');
$command->addOption('-v');
$command->addOption('-L');
$curl = $command->build();
// curl -v -L http://example.com

// change order
$command->setTemplate(Command::TEMPLATE_COMMAND_NAME . Command::TEMPLATE_URL . Command::TEMPLATE_OPTIONS);
$curl = $command->build();
// curl http://example.com -v -L

// remove options
$command->setTemplate(Command::TEMPLATE_COMMAND_NAME . Command::TEMPLATE_URL);
$curl = $command->build();
// curl http://example.com
```

### Quoting and escaping arguments

[](#quoting-and-escaping-arguments)

By default arguments are quoted with single quotes and if single quote appears in the argument it will be escaped

```
$command->addOption('-d', 'data');
// curl -d 'data'

$command->addOption('-d', "data'1");
// curl -d $'data\'1'
```

Quoting character can be changed to double quote or removed

```
$command->addOption('-d', 'data1');
$command->addOption('-d', 'data"2');
$command->setQuoteCharacter(Command::QUOTE_DOUBLE);
// curl -d "data1" -d "data\"2"

$command->addOption('-d', 'data');
$command->setQuoteCharacter(Command::QUOTE_NONE);
// curl -d data

$command->addOption('-d', 'value with spaces');
$command->setQuoteCharacter(Command::QUOTE_NONE);
// curl -d value\ with\ spaces
```

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance56

Moderate activity, may be stable

Popularity46

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 92% 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 ~214 days

Recently: every ~420 days

Total

11

Last Release

440d ago

PHP version history (4 changes)1.0.0PHP ^7.1

1.0.5PHP ^7.1|^8.0

1.0.6PHP &gt;=7.1

1.0.8PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/9946155ed284d2d4147cccc0c9e3fdeaf59310adf1145962d46f6a43820cb4c2?d=identicon)[alexkart](/maintainers/alexkart)

---

Top Contributors

[![alexkart](https://avatars.githubusercontent.com/u/8249105?v=4)](https://github.com/alexkart "alexkart (103 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (4 commits)")[![xepozz](https://avatars.githubusercontent.com/u/6815714?v=4)](https://github.com/xepozz "xepozz (3 commits)")[![samdark](https://avatars.githubusercontent.com/u/47294?v=4)](https://github.com/samdark "samdark (2 commits)")

---

Tags

curlcurl-buildercurl-commandgenerate-curlphppsr-7

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/alexkart-curl-builder/health.svg)

```
[![Health](https://phpackages.com/badges/alexkart-curl-builder/health.svg)](https://phpackages.com/packages/alexkart-curl-builder)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.1B4.4k](/packages/guzzlehttp-psr7)[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k555.0M2.8k](/packages/aws-aws-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k832.6k55](/packages/neuron-core-neuron-ai)[tempest/framework

The PHP framework that gets out of your way.

2.3k37.6k21](/packages/tempest-framework)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

36826.2k2](/packages/telnyx-telnyx-php)[mimmi20/browser-detector

Library to detect Browsers and Devices

49158.4k5](/packages/mimmi20-browser-detector)

PHPackages © 2026

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