GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - cakephp/http: [READONLY] HTTP client and server libraries

BranchesTags
Open more actions menu

Latest commit

 

History

2,343 Commits
2,343 Commits

Folders and files

NameName
Last commit message
Last commit date
Client
Client
 
 
Cookie
Cookie
 
 
Exception
Exception
 
 
Link
Link
 
 
Middleware
Middleware
 
 
RateLimit
RateLimit
 
 
Response
Response
 
 
Session
Session
 
 
TestSuite
TestSuite
 
 
tests
tests
 
 
.gitattributes
.gitattributes
 
 
BaseApplication.php
BaseApplication.php
 
 
CallbackStream.php
CallbackStream.php
 
 
Client.php
Client.php
 
 
ContentTypeNegotiation.php
ContentTypeNegotiation.php
 
 
ControllerFactoryInterface.php
ControllerFactoryInterface.php
 
 
CorsBuilder.php
CorsBuilder.php
 
 
FlashMessage.php
FlashMessage.php
 
 
HeaderUtility.php
HeaderUtility.php
 
 
LICENSE.txt
LICENSE.txt
 
 
MiddlewareApplication.php
MiddlewareApplication.php
 
 
MiddlewareQueue.php
MiddlewareQueue.php
 
 
MimeType.php
MimeType.php
 
 
README.md
README.md
 
 
RequestFactory.php
RequestFactory.php
 
 
Response.php
Response.php
 
 
ResponseEmitter.php
ResponseEmitter.php
 
 
ResponseFactory.php
ResponseFactory.php
 
 
Runner.php
Runner.php
 
 
Server.php
Server.php
 
 
ServerRequest.php
ServerRequest.php
 
 
ServerRequestFactory.php
ServerRequestFactory.php
 
 
Session.php
Session.php
 
 
StreamFactory.php
StreamFactory.php
 
 
UploadedFileFactory.php
UploadedFileFactory.php
 
 
UriFactory.php
UriFactory.php
 
 
composer.json
composer.json
 
 
phpstan.neon.dist
phpstan.neon.dist
 
 

Repository files navigation

Total Downloads License

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

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.

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:

<?php
// in webroot/index.php
require dirname(__DIR__) . '/vendor/autoload.php';

use App\Application;
use Cake\Http\Server;

// Bind your application to the server.
$server = new Server(new Application());

// Run the request/response through the application and emit the response.
$server->emit($server->run());

You can then run your application using PHP's built in webserver:

php -S localhost:8765 -t ./webroot ./webroot/index.php

For more information on middleware, consult the documentation

About

[READONLY] HTTP client and server libraries

Resources

Readme
License
Activity
Custom properties

Stars

5 stars

Watchers

4 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.