There is no license information available for the latest version (v2.1.0) of this package.

v2.1.0 2020-10-28 16:37 UTC

This package is auto-updated.

Last update: 2024-04-29 00:39:23 UTC


Provides traits that add utility functions to a PSR7 ServerResponse subclass that make it easier to interact with the URI and input. Inspired by the API of Laravel.


composer install rareloop/psr7-server-request-extension

Create a ServerRequest

Create a subclass of a PSR7 compatible ServerRequest object (e.g. Diactoros) and add the InteractsWithInput and InteractsWithUri traits.


namespace App;

use Rareloop\Psr7ServerRequestExtension\InteractsWithInput;
use Rareloop\Psr7ServerRequestExtension\InteractsWithUri;
use Zend\Diactoros\ServerRequest;

class MyServerRequest extends ServerRequest
    use InteractsWithInput, InteractsWithUri;


Get the path


Get the URL

$request->url(); // e.g. http://test.com/path
$request->fullUrl(); // e.g. http://test.com/path?foo=bar

Get all query params


Get a specific query param

$request->query('name', 'Jane'); // Defaults to "Jane" if not set

Get all post params


Get a specific post param

$request->post('name', 'Jane'); // Defaults to "Jane" if not set

Get all input params


Get a specific input param

$request->input('name', 'Jane'); // Defaults to "Jane" if not set

Does the request have a specific input key?

if ($request->has('name')) {
    // do something

if ($request->has(['name', 'age'])) {
    // do something if both 'name' and 'age' are present