HTTP client implementation in Hack language

v0.9.0 2021-11-05 00:58 UTC

This package is auto-updated.

Last update: 2023-05-05 04:37:17 UTC



This project implements an HTTP Client in Hack.

  • Simple HTTP Client interface
  • Synchronous and asynchronous requests
  • Middleware support


HHVM 4.132 and above.


  • Git clone this repository

  • Install composer

  • In the root directory of this repository, run the command

      composer install

To use this package,

    composer require ajayvohra2005/hack-http

Running Tests

Testing uses a mock HTTP server written in Node.js. The project was tested with Node.js version v17.0.1. After installation of Node.js and this project, run the following command in the root directory of this repository:

    ./vendor/bin/hacktest tests/

Quick Start Example

use namespace HackHttp\Message as HM;
use namespace HackHttp\Client as HC;

function quick_start(): void 

  $client = new HC\Client();
  // Send a synchronous request.
  $response = $client->request('GET', 'https://docs.hhvm.com/hack/');

  echo $response->getStatusCode(); // 200
  echo $response->getHeaderLine('content-type'); // 'text/html'
  echo $response->getBody()->__toString(); // <!DOCTYPE html><html>...

  // Send an asynchronous request.
  $request = new HM\Request('GET', 'http://httpbin.org');
  $promise = $client->sendAsync($request)->then( (mixed $response): void ==> {
      if($response is HM\Response) {
        echo 'I completed! ' . $response->getBody()->__toString();



Hack Http package is made available under the MIT License (MIT). Please see License File for more information.


The Guzzle, PHP HTTP Client and PSR-7 Message Implementation projects inspired this code.