PHPackages                             michel/httpclient - 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. michel/httpclient

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

michel/httpclient
=================

A lightweight PHP HTTP client library without external dependencies. No need curl extension.

1.0.0(8mo ago)01MITPHPPHP &gt;=7.4

Since Dec 16Pushed 8mo agoCompare

[ Source](https://github.com/michelphp/httpclient)[ Packagist](https://packagist.org/packages/michel/httpclient)[ RSS](/packages/michel-httpclient/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

PHP Http Client
===============

[](#php-http-client)

This PHP HTTP Client provides a minimalistic way to perform `GET` and `POST` HTTP requests with customizable headers. It allows you to handle JSON data, form-encoded requests, and more, without using cURL.

Installation
------------

[](#installation)

You can install this library via [Composer](https://getcomposer.org/). Ensure your project meets the minimum PHP version requirement of 7.4.

```
composer require michel/httpclient
```

Requirements
------------

[](#requirements)

- PHP version 7.4 or higher

Features
--------

[](#features)

- Supports `GET` and `POST` requests.
- Customize headers for each request.
- Automatically handles JSON or form-encoded data.
- Easily configurable base URL for all requests.
- Includes error handling for invalid URLs and timeouts.

Usage
-----

[](#usage)

### Basic GET Request

[](#basic-get-request)

```
use Michel\HttpClient\HttpClient;

$client = new HttpClient(['base_url' => 'http://example.com']);

// Perform a GET request
$response = $client->get('/api/data');

if ($response->getStatusCode() === 200) {
    echo $response->getBody(); // Raw response body
    print_r($response->bodyToArray()); // JSON decoded response
}
```

### GET Request with Query Parameters

[](#get-request-with-query-parameters)

```
$response = $client->get('/api/search', ['query' => 'test']);
```

### POST Request (Form-Encoded)

[](#post-request-form-encoded)

```
$data = [
    'username' => 'testuser',
    'password' => 'secret'
];

$response = $client->post('/api/login', $data);
```

### POST Request (JSON)

[](#post-request-json)

```
$data = [
    'title' => 'Hello World',
    'content' => 'This is a post content'
];

$response = $client->post('/api/posts', $data, true); // `true` specifies JSON content type
```

### Custom Headers

[](#custom-headers)

```
$client = new HttpClient([
    'base_url' => 'http://example.com',
    'headers' => ['Authorization' => 'Bearer your_token']
]);

$response = $client->get('/api/protected');
```

---

Helper Functions
----------------

[](#helper-functions)

To make the HTTP client easier to use, we provide a set of helper functions that allow you to quickly send `GET` and `POST` requests without needing to manually instantiate the `HttpClient` class every time.

### Available Helper Functions

[](#available-helper-functions)

#### 1. `http_client()`

[](#1-http_client)

This function creates and returns a new `HttpClient` instance with the provided configuration options.

```
$client = http_client([
    'base_url' => 'http://example.com',
    'headers' => ['Authorization' => 'Bearer your_token']
]);
```

#### 2. `http_post()`

[](#2-http_post)

Use this function to make a POST request with form-encoded data. It sends a request to the given URL with optional data and headers.

```
$response = http_post('http://example.com/api/login', [
    'username' => 'user123',
    'password' => 'secret'
]);
```

#### 3. `http_post_json()`

[](#3-http_post_json)

This function sends a POST request with JSON-encoded data. Useful for APIs expecting JSON input.

```
$response = http_post_json('http://example.com/api/create', [
    'title' => 'New Post',
    'body' => 'This is the content of the new post.'
]);
```

#### 4. `http_get()`

[](#4-http_get)

Make a GET request using this function. You can include query parameters and headers as needed.

```
$response = http_get('http://example.com/api/users', [
    'page' => 1,
    'limit' => 10
]);
```

### Example Usage of Helpers

[](#example-usage-of-helpers)

```
// Make a GET request
$response = http_get('http://api.example.com/items', ['category' => 'books']);
$data = $response->bodyToArray();

// Make a POST request with form data
$response = http_post('http://api.example.com/login', [
    'username' => 'user123',
    'password' => 'secret'
]);

// Make a POST request with JSON data
$response = http_post_json('http://api.example.com/posts', [
    'title' => 'Hello World',
    'content' => 'This is my first post!'
]);
```

These helper functions simplify making HTTP requests by reducing the need to manually create and configure the `HttpClient` for each request.

###  Health Score

27

—

LowBetter than 46% of packages

Maintenance61

Regular maintenance activity

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

245d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/909a078010ad44ff35146af8288451a3b6fd26f81cb198cbea776a92553c9b8a?d=identicon)[F.Michel](/maintainers/F.Michel)

---

Top Contributors

[![michelphp](https://avatars.githubusercontent.com/u/26349908?v=4)](https://github.com/michelphp "michelphp (1 commits)")

### Embed Badge

![Health badge](/badges/michel-httpclient/health.svg)

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

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25026.8M85](/packages/php-http-cache-plugin)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

85997.3k131](/packages/httpsoft-http-message)[thesis/nats

Async (fiber based) client for Nats.

758.3k](/packages/thesis-nats)

PHPackages © 2026

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