PHPackages                             cakephp/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. [Framework](/categories/framework)
4. /
5. cakephp/http

ActiveLibrary[Framework](/categories/framework)

cakephp/http
============

CakePHP HTTP client and PSR-7, PSR-15, PSR-17, PSR-18 compliant libraries

5.3.3(2mo ago)517.9k↓49.5%15MITPHPPHP &gt;=8.2

Since Nov 13Pushed 1mo ago4 watchersCompare

[ Source](https://github.com/cakephp/http)[ Packagist](https://packagist.org/packages/cakephp/http)[ Docs](https://cakephp.org)[ RSS](/packages/cakephp-http/feed)WikiDiscussions 5.x Synced 1mo ago

READMEChangelogDependencies (32)Versions (141)Used By (5)

[![Total Downloads](https://camo.githubusercontent.com/668f4e58f92e82569693ce3e70a3b57cccd223eb1cefcb5c541dac4dbd0101c3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63616b657068702f687474702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cakephp/http)[![License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE.txt)

CakePHP Http Library
====================

[](#cakephp-http-library)

This library provides a PSR-15 Http middleware server, PSR-7 Request and Response objects, PSR-17 HTTP Factories, and PSR-18 Http Client. Together these classes let you handle incoming server requests and send outgoing HTTP requests.

Using the Http Client
---------------------

[](#using-the-http-client)

Sending requests is straight forward. Doing a GET request looks like:

```
use Cake\Http\Client;

$http = new Client();

// Simple get
$response = $http->get('http://example.com/test.html');

// Simple get with querystring
$response = $http->get('http://example.com/search', ['q' => 'widget']);

// Simple get with querystring & additional headers
$response = $http->get('http://example.com/search', ['q' => 'widget'], [
  'headers' => ['X-Requested-With' => 'XMLHttpRequest'],
]);
```

To learn more read the [Http Client documentation](https://book.cakephp.org/5/en/core-libraries/httpclient.html).

Using the Http Server
---------------------

[](#using-the-http-server)

The Http Server allows an `HttpApplicationInterface` to process requests and emit responses. To get started first implement the `Cake\Http\HttpApplicationInterface` A minimal example could look like:

```
namespace App;

use Cake\Core\HttpApplicationInterface;
use Cake\Http\MiddlewareQueue;
use Cake\Http\Response;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

class Application implements HttpApplicationInterface
{
    /**
     * Load all the application configuration and bootstrap logic.
     *
     * @return void
     */
    public function bootstrap(): void
    {
        // Load configuration here. This is the first
        // method Cake\Http\Server will call on your application.
    }

    /**
     * Define the HTTP middleware layers for an application.
     *
     * @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to set in your App Class
     * @return \Cake\Http\MiddlewareQueue
     */
    public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
    {
        // Add middleware for your application.
        return $middlewareQueue;
    }

    /**
     * Handle incoming server request and return a response.
     *
     * @param \Psr\Http\Message\ServerRequestInterface $request The request
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function handle(ServerRequestInterface $request): ResponseInterface
    {
        return new Response(['body'=>'Hello World!']);
    }
}
```

Once you have an application with some middleware. You can start accepting requests. In your application's webroot, you can add an `index.php` and process requests:

```
