PHP Classes

File: public/app.responder.receiver.php

Recommend this page to a friend!
  Packages of Engin Ypsilon   Curler PHP HTTP Client Library   public/app.responder.receiver.php   Download  
File: public/app.responder.receiver.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Curler PHP HTTP Client Library
Send HTTP requests setup using a fluent interface
Author: By
Last change: ## [2.0.0] - 2026-07-22

### Added
- HTTP QUERY Method (RFC 9204) support
- Response Pipeline with callbacks and validation
- Full type-safety with PHP 8 types
- Meta-information for each request
- Retry logic with configurable attempts
- HTTP/2 default

### Changed
- Response objects instead of arrays
- `callback()` → `through()` for pipeline
- `readableBytes()` → `formatBytes()`
- `getCurlTrace()` → `getHistory()`

### Deprecated
- Old callback system (use pipeline instead)
- `postFields()` → `withForm()` or `withJson()`
Date: 4 months ago
Size: 1,409 bytes
 

 

Contents

Class file image Download
<?php

/**
 * Example Receiver / Responder
 */

/**
 * Curler Responder, let's say 'https://example.com/restricted/' is .htaccess protected and returns
 */

use Many\Http\Curler;

$rspns = [
    'auth_type' => $_SERVER['AUTH_TYPE'] ?? 'error',
    'header' => getallheaders(),
    'body' => file_get_contents('php://input'),
    'c_types' => [
        'json' => 'application/json',
    ]
];

$setType = $rspns['c_types'][$_GET['c_type'] ?? null] ?? null;
$cType = $setType ?? $_SERVER['CONTENT_TYPE'] ?? 'text/html';

/** Set Content-Type header auto, if requested one is listed in 'c_types' */
if ($setType)
    header(sprintf('Content-Type: %s; charset: %s', $cType, $_GET['charset'] ?? 'UTF-8'));

/** Parse received body content */
if (ctype_print($rspns['body']))
    parse_str($rspns['body'], $rspns['body_parsed']);

exit('application/json' == $cType
    ? json_encode($rspns, JSON_PRETTY_PRINT)
    : print_r($rspns, true)
);



/**
 * Curler Receiver, access the .htaccess protected ressources
 */

$curler = (new Curler)
    ->authAny('many', '123456') // auto ->authBasic() or ->authDigest()
    ->postFields([
        'lorem_ipsum' => 'Dolor Sit Amet',
    ])
    ->jsonDecode()
    ->exec('https://example.com/restricted/'); // ?c_type=json &charset=UTF-8

printf('<pre>%s<hr /><b>body</b><br />%s</pre>'
    , print_r($curler, true)
    , $curler['response']->body ?? 'body is not an object'
);