PHPackages                             dbeurive/http - 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. dbeurive/http

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

dbeurive/http
=============

This package implements a simple REST requester

1.0.1(7y ago)06MITPHPPHP &gt;=5.6.0

Since Nov 1Pushed 7y ago1 watchersCompare

[ Source](https://github.com/dbeurive/http)[ Packagist](https://packagist.org/packages/dbeurive/http)[ RSS](/packages/dbeurive-http/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Introduction
============

[](#introduction)

This package implements a simple wrapper around the Curl library that makes the development of REST clients easier.

Installation
============

[](#installation)

From the command line:

```
composer require dbeurive/http

```

Or, from within the file composer.json:

```
"require": {
    "dbeurive/http": "*"
}

```

Synopsis
========

[](#synopsis)

Basic usage
-----------

[](#basic-usage)

```
require_once  '/path/to/autoload.php';

use dbeurive\Http\Requester;
use dbeurive\Http\ExceptionParameter;
use dbeurive\Http\ExceptionRuntime;
use dbeurive\Http\Code;

// ---------------------------------------------
// GET / DELETE
// ---------------------------------------------

// Create a requester.
// Through the constructor's second parameter, you can provide a setting that will be applied for all requests.
// Here, we set the required header for a basic authentication.
$general_curl_options = array(CURLOPT_USERPWD => 'login:password');
$requester = new Requester($general_curl_options);

$report = null;
try {
    // Send a GET request.
    // Through the method's second parameter, you can provide a setting that will be applied for this request only.
    // The method returns an "execution report". This report contains:
    // - the request that has been sent (the header and the content).
    // - the response that has been received (the header and the body).
    // - information returned by the Curl library (such as the request duration).
    $specific_curl_options = array(CURLOPT_HTTPHEADER => array(
        'header1: a',
        'header2: b',
    ));
    $report = $requester->doGet('http://www.google.com/search?q=php',
        $specific_curl_options); // This parameter is optional.
} catch (ExceptionRuntime $e) {
    printf("FATAL ERROR: %s\n", $e->getMessage());
    exit(1);
} catch (ExceptionParameter $e) {
    printf("FATAL ERROR: %s\n", $e->getMessage());
    exit(1);
} catch (\Exception $e) {
    printf("FATAL ERROR: %s\n", $e->getMessage());
    exit(1);
}

$http_code = $report->getResponse()->getCode();
printf("Last HTTP response code: %d\n", $http_code);
printf("Content length:          %d\n", $report->getResponse()->getContentLength());
printf("Content type:            %s\n\n", is_null($report->getResponse()->getContentType()) ? 'null' : $report->getResponse()->getContentType());

if (Code::HTTP_OK != $http_code) {
    printf("HTTP code: %d (%s)\n\n",
        $http_code,
        Code::getDescription($http_code)
    );
}

// Get the request header. Please note that the request content will be null (as it is for any GET request).
printf("Request header:\n\n%s\n\n",
    $report->getRequest()->getHeader()->getAsString()
);

// Get the response header.
printf("Response header:\n\n%s\n\n",
    $report->getResponse()->getHeader()->getAsString()
);

// Get the response body.
printf("Request body:\n\n%s\n\n",
    $report->getResponse()->getBody()
);

// Get data about the execution.
printf("Request body:\n\n%s\n\n",
    $report->getInformation()->getAsString(true)
);

// ---------------------------------------------
// POST / PUT
// ---------------------------------------------

// Create a requester.
// Note: a requester is not bound to a URL or a method. We could have reused the one you've previously created (for the
//       GET example).
$general_curl_options = array(); // No setting is provided for all requests.
$requester = new Requester($general_curl_options); // Note: the parameter is optional.

define('HOST', 'localhost');
define('PORT', 8000);

$query_string = '/handle_post.php';
$url = sprintf('http://%s:%d%s', HOST, PORT, $query_string);
$content = 'var=value';

$specific_curl_options = array(CURLOPT_HTTPHEADER => array(
    'header1: a',
    'header2: b',
));
$report = null;
try {
    $report = $requester->doPost($url,
        $content,
        'text/html',
        $specific_curl_options); // This parameter is optional.
} catch (ExceptionRuntime $e) {
    printf("FATAL ERROR: %s\n", $e->getMessage());
    exit(1);
} catch (ExceptionParameter $e) {
    printf("FATAL ERROR: %s\n", $e->getMessage());
    exit(1);
} catch (\Exception $e) {
    printf("FATAL ERROR: %s\n", $e->getMessage());
    exit(1);
}

printf("Last HTTP response code: %d\n", $report->getResponse()->getCode());
printf("Content length:          %d\n", $report->getResponse()->getContentLength());
printf("Content type:            %s\n\n", is_null($report->getResponse()->getContentType()) ? 'null' : $report->getResponse()->getContentType());

// Get the request header. Please note that the request content will be null (as it is for any GET request).
printf("Request header:\n\n%s\n\n",
    $report->getRequest()->getHeader()->getAsString()
);

// Get the request content.
printf("Request content:\n\n%s\n\n",
    $report->getRequest()->getContent()
);

// Get the response header.
printf("Response header:\n\n%s\n\n",
    $report->getResponse()->getHeader()->getAsString()
);

// Get the response body.
printf("Request body:\n\n%s\n\n",
    $report->getResponse()->getBody()
);

// Get data about the execution.
printf("Request body:\n\n%s\n\n",
    $report->getInformation()->getAsString(true)
);

```

Advanced usage
--------------

[](#advanced-usage)

You can create your own customised requesters.

```
class MyRequester extends AbstractRequester {

    // ...

    /**
     * Perform a GET request.
     * @param string $in_url The URL.
     * @param array $in_opt_additional_curl_options Additional CURL options.
     * @return Report The execution report.
     * @throws ExceptionParameter
     * @throws ExceptionRuntime
     */
    public function doGet($in_url, array $in_opt_additional_curl_options=array()) {
        // ...
        return parent::_doGet($in_url, $in_opt_additional_curl_options);
    }

    /**
     * Perform a POST request.
     * @param string $in_url The URL.
     * @param string $in_content The request content.
     * @param string $in_content_type The content type.
     * @param array $in_opt_additional_curl_options $in_additional_curl_options Additional CURL options.
     * @return Report The execution report.
     * @throws ExceptionParameter
     * @throws ExceptionRuntime
     */
    public function doPost($in_url, $in_content, $in_content_type, array $in_opt_additional_curl_options=array()) {
        // ...
        return parent::_doPost($in_url, $in_content, $in_content_type, $in_opt_additional_curl_options);
    }

    /**
     * Perform a PUT request.
     * @param string $in_url The URL.
     * @param string $in_content The request content.
     * @param string $in_content_type The content type.
     * @param array $in_opt_additional_curl_options $in_additional_curl_options Additional CURL options.
     * @return Report The execution report.
     * @throws ExceptionParameter
     * @throws ExceptionRuntime
     */
    public function doPut($in_url, $in_content, $in_content_type, array $in_opt_additional_curl_options=array()) {
        // ...
        return parent::_doPut($in_url, $in_content, $in_content_type, $in_opt_additional_curl_options);
    }

    /**
     * Perform a DELETE request.
     * @param string $in_url The URL.
     * @param array $in_opt_additional_curl_options Additional CURL options.
     * @return Report The execution report.
     * @throws ExceptionParameter
     * @throws ExceptionRuntime
     */
    public function doDelete($in_url, array $in_opt_additional_curl_options=array()) {
        // ...
        return parent::_doDelete($in_url, $in_opt_additional_curl_options);
    }

    // ...
}

```

Examples
========

[](#examples)

The directory ["examples"](examples) contains several examples:

- [get.php](examples/get.php)
- [post.php](examples/post.php)
- [put.php](examples/put.php)
- [delete.php](examples/delete.php)
- [synopsis.php](examples/synopsis.php)

Please note that in order to run these examples, you need to start PHP as a WEB server, as described below:

```
cd tests
php -S localhost:8000 -t public

```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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 ~0 days

Total

2

Last Release

2750d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18211524?v=4)[Denis BEURIVE](/maintainers/dbeurive)[@dbeurive](https://github.com/dbeurive)

---

Top Contributors

[![dbeurive](https://avatars.githubusercontent.com/u/18211524?v=4)](https://github.com/dbeurive "dbeurive (6 commits)")

---

Tags

httprequest

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dbeurive-http/health.svg)

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.0B3.2k](/packages/guzzlehttp-psr7)[psr/http-message

Common interface for HTTP messages

7.1k1.0B5.5k](/packages/psr-http-message)[psr/http-factory

PSR-17: Common interfaces for PSR-7 HTTP message factories

1.9k692.9M1.9k](/packages/psr-http-factory)[fig/http-message-util

Utility classes and constants for use with PSR-7 (psr/http-message)

39489.0M274](/packages/fig-http-message-util)[nette/http

🌐 Nette Http: abstraction for HTTP request, response and session. Provides careful data sanitization and utility for URL and cookies manipulation.

48619.2M541](/packages/nette-http)[psr/http-server-handler

Common interface for HTTP server-side request handler

175101.3M921](/packages/psr-http-server-handler)

PHPackages © 2026

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