PHPackages                             weew/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. [HTTP &amp; Networking](/categories/http)
4. /
5. weew/http

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

weew/http
=========

Basic http layer.

v1.13.0(9y ago)14667MITPHP

Since Jul 21Pushed 9y ago1 watchersCompare

[ Source](https://github.com/weew/http)[ Packagist](https://packagist.org/packages/weew/http)[ RSS](/packages/weew-http/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (7)Versions (50)Used By (7)

HTTP layer for PHP
==================

[](#http-layer-for-php)

[![Build Status](https://camo.githubusercontent.com/bd2657304ce781b221cce883af896535ae043e3751df057d19380849f1d82eb4/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f776565772f687474702e737667)](https://travis-ci.org/weew/http)[![Code Quality](https://camo.githubusercontent.com/d86f72c4b6754d18d07ab11d3d6d4a7633b3cb1f0e4619d75d6b92b3e330a2b0/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f776565772f687474702e737667)](https://scrutinizer-ci.com/g/weew/http)[![Test Coverage](https://camo.githubusercontent.com/9386b83f026c270204165cee113762a40dd240896cd96cc3f18e06824e038623/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f776565772f687474702e737667)](https://coveralls.io/github/weew/http)[![Version](https://camo.githubusercontent.com/9972a3606cf052966d5b4cfc2077e24f16098984d3e1847b0c72121191ef55a5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f776565772f687474702e737667)](https://packagist.org/packages/weew/http)[![Licence](https://camo.githubusercontent.com/cfc6ca103176fea920e606c45a974945e9b0b71adf27368cff6d671cf719d90e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f776565772f687474702e737667)](https://packagist.org/packages/weew/http)

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Responses](#responses)
    - [Basic response](#basic-response)
    - [Content](#content)
    - [Status codes](#status-codes)
    - [Headers](#headers)
    - [Cookies](#cookies)
    - [Custom responses](#custom-responses)
        - [HtmlResponse](#htmlresponse)
        - [JsonResponse](#jsonresponse)
        - [BasicAuthResponse](#basicauthresponse)
- [Requests](#requests)
    - [Basic request](#basic-request)
    - [GET parameters](#get-parameters)
    - [POST data](#post-data)
    - [Headers](#headers)
    - [Current request](#current-request)
    - [Basic authentication](#basic-authentication)
- [Related projects](#related-projects)

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

[](#installation)

`composer require weew/http`

Responses
---------

[](#responses)

### Basic response

[](#basic-response)

```
$response = new HttpResponse();
$response->send();
```

```
HTTP/1.1 200 OK
Host: localhost
Connection: close

```

### Content

[](#content)

```
$response = new HttpResponse();
$response->setContent('Hello World!');
$response->send();
```

```
HTTP/1.1 200 OK
Host: localhost
Connection: close
content-type: text/html

Hello World!

```

### Status codes

[](#status-codes)

```
$response = new HttpResponse(HttpStatusCode::UNAUTHORIZED);
// or
$response = new HttpResponse(401);
$response->send();
```

```
HTTP/1.1 401 Unauthorized
Host: localhost
Connection: close

```

### Headers

[](#headers)

```
$response = new HttpResponse();
$response->getHeaders()->set('foo', 'bar');
$response->send();
```

```
HTTP/1.1 200 OK
Host: localhost
Connection: close
foo: bar

```

### Cookies

[](#cookies)

```
$response = new HttpResponse();
$response->getQueuedCookies()->add(new Cookie('foo', 'bar'));
$response->send();
```

```
HTTP/1.1 200 OK
Host: localhost
Connection: close
set-cookie: foo=bar; path=/; httpOnly

```

Custom responses
----------------

[](#custom-responses)

### HtmlResponse

[](#htmlresponse)

```
$response = new HtmlResponse();
$response->setHtmlContent('Hello World!');
$response->send();
```

```
HTTP/1.1 200 OK
Host: localhost
Connection: close
content-type: text/html

Hello World!

```

### JsonResponse

[](#jsonresponse)

```
$response = new JsonResponse();
$response->getData()->set('Hello', 'World!');
$response->send();
```

```
HTTP/1.1 200 OK
Host: localhost
Connection: close
content-type: application/json

{"Hello":"World!"}

```

### BasicAuthResponse

[](#basicauthresponse)

```
$response = new BasicAuthResponse('Please login');
$response->send();
```

```
HTTP/1.1 200 OK
Host: localhost
Connection: close
www-authenticate: basic realm="Please login"

```

Requests
--------

[](#requests)

### Basic request

[](#basic-request)

It is very easy to build a custom request.

```
$request = new HttpRequest(
    HttpRequestMethod::POST,
    new Url('http://example.com')
);
$request->setContent('foo=bar');
```

### GET parameters

[](#get-parameters)

```
$request = new HttpRequest();
$request->getUrl()->getQuery()->set('foo', 'bar');

echo $request->getUrl()->getQuery();
// foo=bar
```

### POST data

[](#post-data)

```
$request = new HttpRequest();
$request->getData()->set('foo', 'bar');
$request->getData()->set('bar', 'foo');

echo $request->getContent();
// foo=bar&bar=foo
```

### Headers

[](#headers-1)

You can access headers the same way as on the `HttpResponse` class.

```
$request = new HttpRequest();
$request->getHeaders()->set('foo', 'bar');
$request->getHeaders()->add('foo', 'foo');

var_dump($request->getHeaders()->get('foo'));
// ['bar', 'foo']
echo $request->getHeaders()->find('foo');
// foo
```

### Current Request

[](#current-request)

Sometimes it is nice to have an object that would represent the current received http request.

```
$request = new CurrentRequest();
var_dump($request->toArray());
// all the data that the server received from the client
```

### Basic Authentication

[](#basic-authentication)

It is very easy to authenticate a request via basic auth.

```
$request = new HttpRequest();
$request->getBasicAuth()->setUsername('foo');
$request->getBasicAuth()->setPassword('bar');
echo $request->getBasicAuth()->getToken();
// Zm9vOmJhcg==
echo $request->getHeaders()->find('authentication');
// Basic Zm9vOmJhcg==
```

Related Projects
----------------

[](#related-projects)

- [URL](https://github.com/weew/url): used throughout the project.
- [HTTP Client](https://github.com/weew/http-client): a simple http client that allows you to send and receive the standardized HttpRequest and HttpResponse objects.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity76

Established project with proven stability

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

Recently: every ~38 days

Total

49

Last Release

3527d ago

Major Versions

v0.1.19 → v1.0.02015-11-16

### Community

Maintainers

![](https://www.gravatar.com/avatar/10b2b854b5829dd13a15967c000ed2119b5faef67aca24d94c653c8ac550d85e?d=identicon)[weew](/maintainers/weew)

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25126.1M81](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.9M6.8k](/packages/illuminate-http)[magento/magento2-functional-testing-framework

Magento2 Functional Testing Framework

15312.0M36](/packages/magento-magento2-functional-testing-framework)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k24.3k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

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

87965.9k114](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.4M89](/packages/mezzio-mezzio-router)

PHPackages © 2026

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