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(11mo ago)19395.6k↑11.2%4[1 PRs](https://github.com/alexkart/curl-builder/pulls)2MITPHPPHP &gt;=7.3CI passing

Since Jul 25Pushed 3mo 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 1mo 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

51

—

FairBetter than 96% of packages

Maintenance67

Regular maintenance activity

Popularity45

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

349d 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

[league/uri-interfaces

Common tools for parsing and resolving RFC3987/RFC3986 URI

536204.9M23](/packages/league-uri-interfaces)[shopify/shopify-api

Shopify API Library for PHP

4634.8M16](/packages/shopify-shopify-api)[laudis/neo4j-php-client

Neo4j-PHP-Client is the most advanced PHP Client for Neo4j

184616.9k31](/packages/laudis-neo4j-php-client)[http-interop/response-sender

A function to convert PSR-7 Response to HTTP output

46711.5k40](/packages/http-interop-response-sender)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)

PHPackages © 2026

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