Search by

byjg / webrequest

byjg

A lightweight PSR-7 implementation and highly customized CURL wrapper for making REST calls.

Package info

github.com/byjg/php-webrequest

pkg:composer/byjg/webrequest

Statistics

Installs: 574 475

Dependents: 11

Suggesters: 1

Stars: 6

Open Issues: 0

6.0.0 2025-11-22 05:25 UTC

README

sidebar_key webrequest
sidebar_category http-apis
tags
php http

Web Request

A PSR-18 HTTP client on cURL, with its own PSR-7 messages, parallel requests and a mock client for tests, in one small package.

Sponsor Build Status Opensource ByJG Install MCP Server GitHub source GitHub license GitHub release

Why

Calling an API should not need a large dependency tree, and the code that does it should be easy to test. Most clients give you one of the two.

WebRequest implements the standards (PSR-7 messages, PSR-17 factories, a PSR-18 client), so the code that uses it depends on the interfaces, not on this package:

$responses = HttpPromise::all(
    users:  $httpClient->sendAsync(Request::getInstance(Uri::getInstance('https://api.example.com/users'))),
    orders: $httpClient->sendAsync(Request::getInstance(Uri::getInstance('https://api.example.com/orders'))),
)->await();
  • Parallel requests without an event loop. sendAsync() returns a promise, and every pending request runs together on cURL multi when you await().
  • Test without the network. MockClient returns the response you give it and keeps the request it received.
  • Helpers for the usual bodies: JSON, form URL-encoded and multipart.

Overview

PHP WebRequest is a fully PSR-compliant HTTP client package that provides:

PSR Implementations

  • ✅ PSR-7 - HTTP Message Interface (Request, Response, Stream)
  • ✅ PSR-17 - HTTP Factories (Request, Response, Stream, etc.)
  • ✅ PSR-18 - HTTP Client Interface

Additional Features

  • Helper classes for common request types (JSON, Form URL Encoded, MultiPart)
  • Support for parallel HTTP requests, with promises (sendAsync()) or callbacks
  • Mock client for testing

Documentation

Basic Example

<?php
// Create a request
$uri = \ByJG\Util\Uri::getInstance('http://www.example.com/page');
$request = \ByJG\WebRequest\Psr7\Request::getInstance($uri);

// Send the request
$response = \ByJG\WebRequest\HttpClient::getInstance()->sendRequest($request);

// Process the response
$statusCode = $response->getStatusCode();
$body = $response->getBody()->getContents();

Installation

composer require "byjg/webrequest"

Running Tests

# Start the test server
docker-compose up -d

# Run the tests
vendor/bin/phpunit

# Stop the server
docker-compose down

Open source ByJG