2017 © Pedro Peláez
 

library http

Neat HTTP components

image

neat/http

Neat HTTP components

  • Sunday, July 29, 2018
  • by guidovanbiemen
  • Repository
  • 2 Watchers
  • 0 Stars
  • 44 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 3 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Neat HTTP components

Stable Version Build Status, (*1)

Neat HTTP components provide a clean and expressive API for your application to access HTTP messages., (*2)

Requirements

To use Neat HTTP components you will need - PHP 7.0 or newer - a PSR-7 HTTP message implementation, (*3)

To send and receive messages, we suggest using the neat/http-client and neat/http-server packages., (*4)

Getting started

To install this package, simply issue composer on the command line:, (*5)

composer require neat/http

Reading the request

The request can be read using simple methods like shown below., (*6)

<?php /** @var Neat\Http\ServerRequest $request */

// Get ?page= query parameter
$page = $request->query('page');

// Get posted name field
$name = $request->post('name');

// Or just get all posted fields
$post = $request->post();

// Who doesn't want a cookie
$preference = $request->cookie('preference');

// Get the request method
$method = $request->method();

// And of course the requested URL
$url = $request->url();

URL inspection

To save you the trouble of dissecting and concatenating URL's by hand, the URL class will lend you a hand:, (*7)

<?php /** @var Neat\Http\Url $url */

// You can easily print the URL because it converts to a string when needed
echo $url;

// Or get parts of the url separately
$url->scheme();   // 'https'
$url->username(); // ''
$url->password(); // ''
$url->host();     // 'example.com'
$url->port();     // null
$url->path();     // '/articles'
$url->query();    // 'page=2'
$url->fragment(); // ''

// Do you want to create a slightly different URL based on this one?
$mutation = $url->withPath('/just')->withQuery('tweak=any&part=youlike');

File uploads

Uploaded files can be accessed through the request using the file method., (*8)

<?php /** @var Neat\Http\ServerRequest $request */

// Get uploaded file with the name avatar
$file = $request->files('avatar');

// Check the error status
if (!$file->ok()) {
    echo 'Upload error id = ' . $file->error();
}

// Get the file name, size and mime type
$file->clientName(); // 'selfie.jpg' <-- provided by the client, so consider it unsafe user input
$file->clientType(); // 'image/jpeg' <-- provided by the client, so consider it unsafe user input
$file->size(); // 21359

// Move the file from its temporary location
$file->moveTo('destination/path/including/filename.jpg');

The Versions

29/07 2018

dev-feature/router

dev-feature/router

Neat HTTP components

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

http request response

14/07 2018

dev-master

9999999-dev

Neat HTTP components

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

http request response