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

ActiveLibrary

xpat/xpat-http
==============

Http requests library.

v1.0.2(1y ago)091MITPHPPHP &gt;=8.3

Since Dec 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/xpat23/xpat-http)[ Packagist](https://packagist.org/packages/xpat/xpat-http)[ RSS](/packages/xpat-xpat-http/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (1)

Simple Object-Oriented HTTP Client
==================================

[](#simple-object-oriented-http-client)

A simple and intuitive object-oriented HTTP client for PHP. This library enables you to make HTTP requests (GET, POST, PUT, DELETE) with clean, structured code.

Features
--------

[](#features)

- Object-oriented design.
- Supports common HTTP methods: GET, POST, PUT, DELETE.
- Easily configurable headers and request body.
- Straightforward and reusable components for URL, headers, and body.

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

[](#installation)

```
composer require xpat/xpat-http
```

Usage
-----

[](#usage)

### GET Request Example

[](#get-request-example)

```
use Xpat\Http\Request\Get;
use Xpat\Http\Request\Headers;
use Xpat\Http\Request\Url;

$response = (
    new Get(
        new Url(
            'localhost',
            8080,
            '/expense-categories'
        ),
        new Headers([
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
        ])
    )
)->execute();

echo $response->content() . PHP_EOL;
echo $response->statusCode() . PHP_EOL;
```

### POST Request Example

[](#post-request-example)

```
use Xpat\Http\Request\Headers;
use Xpat\Http\Request\JsonBody;
use Xpat\Http\Request\Post;
use Xpat\Http\Request\Url;

$response = (
    new Post(
        new Url(
            'localhost',
            8080,
            '/expense-categories'
        ),
        new Headers([
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
        ]),
        new JsonBody([
            'name' => 'New Category',
        ])
    )
)->execute();

echo $response->content() . PHP_EOL;
echo $response->statusCode() . PHP_EOL;
```

### PUT Request Example

[](#put-request-example)

```
use Xpat\Http\Request\Headers;
use Xpat\Http\Request\JsonBody;
use Xpat\Http\Request\Put;
use Xpat\Http\Request\Url;

$response = (
    new Put(
        new Url(
            'localhost',
            8080,
            '/expense-categories/4'
        ),
        new Headers([
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
        ]),
        new JsonBody([
            'id' => 4,
            'name' => 'Grocery',
        ])
    )
)->execute();

echo $response->content() . PHP_EOL;
echo $response->statusCode() . PHP_EOL;
```

### DELETE Request Example

[](#delete-request-example)

```
use Xpat\Http\Request\Delete;
use Xpat\Http\Request\Headers;
use Xpat\Http\Request\Url;

$response = (
    new Delete(
        new Url(
            'localhost',
            8080,
            '/expense-categories/4'
        ),
        new Headers([
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
        ])
    )
)->execute();

echo $response->content() . PHP_EOL;
echo $response->statusCode() . PHP_EOL;
```

Components
----------

[](#components)

### `Url`

[](#url)

Defines the request URL, including the host, port, and endpoint.

### `Headers`

[](#headers)

Manages HTTP headers as key-value pairs.

### `JsonBody`

[](#jsonbody)

Formats and encapsulates the request body as JSON.

### Response Object

[](#response-object)

The `execute()` method returns a response object with the following methods:

- `content()`: The content of the HTTP response.
- `statusCode()`: The HTTP status code of the response.

### `JsonObject`

[](#jsonobject)

The JsonObject class provides a simple and powerful way to work with JSON data in an object-oriented manner. It allows you to parse, query, and manipulate JSON structures using a key-path syntax.

#### Example

[](#example)

```
use Xpat\Http\Json\JsonObject;

$json = new JsonObject(
    '{
        "id": 3,
        "amount": 300,
        "description": "Plain ticket",
        "date": "2024-11-27 22:47:21",
        "category": {
            "id": 2,
            "name": "Travel"
        }
    }'
);

if ($json->has('category.name')) {
    echo $json->get('category.name');
} else {
    echo 'No category name found';
}
```

License
-------

[](#license)

The MIT License (MIT)

Copyright (c) 2024 Alymbek Kydyrmyshev

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

30

—

LowBetter than 65% of packages

Maintenance42

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

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

Total

3

Last Release

484d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cefa6361c95c37e9bf088b67948e7eb62c0c22b19b917c724a87a41a92b5da2f?d=identicon)[xpat23](/maintainers/xpat23)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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