PHP code example of phpraptor / request

1. Go to this page and download the library: Download phpraptor/request library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phpraptor / request example snippets


use Raptor\Request\Http;

$request = new Http;

$request->line();    // request-line
$request->header();  // header fields
$request->body();    // message body

$request->line()->method();   // method token
$request->line()->target();   // request-target
$request->line()->version();  // HTTP-version

$request->line()->method();
$request->method();    // short approach

// Example output:
'POST'

$request->line()->target()->path();

// Example output:
'/company/about'

$request->line()->target()->query();
$request->query();    // short approach

// Example output:
[
    'search' => 'john doe',
    'page' => '2'
]

$request->line()->target()->query('search');
$request->query('search');    // short approach

// Example output:
'john doe'

$request->line()->target()->query('search', 'default value');
$request->query('search', 'default value');    // short approach

// Example output:
'default value'

$request->line()->version();

// Example output:
'HTTP/1.1'

$request->header()->all();

// Example output:
[
    'HTTP_HOST' => 'localhost',
    'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0',
    'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.5',
    'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
    'HTTP_COOKIE' => 'PHPSESSID=t8ih495a8fap4agrkk9ectn2r5',
    'HTTP_CONNECTION' => 'keep-alive'
]

$request->header()->get('HTTP_HOST');

// Example output:
'localhost'

$request->header()->get('HTTP_EXAMPLE', 'default value');

// Example output:
'default value'

$request->header()->cookie();
$request->cookie();    // short approach

// Example output:
[
    'PHPSESSID' => 'lopaavhboml1ua6a539b8u0rm7'
]

$request->header()->cookie('PHPSESSID');
$request->cookie('PHPSESSID');    // short approach

// Example output:
'lopaavhboml1ua6a539b8u0rm7'

$request->header()->cookie('FONTSIZE', '14px');
$request->cookie('FONTSIZE', '14px');    // short approach

// Example output:
'14px'

$request->body()->param();
$request->param();    // short approach

// Example output:
[
    'username' => 'phpraptor',
    'password' => 'johndoe'
]

$request->body()->param('username');
$request->param('username');    // short approach

// Example output:
'phpraptor'

$request->body()->param('category_id', 30);
$request->param('category_id', 30);    // short approach

// Example output:
30

$request->body()->files();
$request->uploads();    // short approach

// Example output:
[
    'image' => [
        'name' => 'image01.jpg',
        'type' => 'image/jpeg',
        'tmp_name' => '\path\to\tmp\php2660.tmp',
        'error' => 0,
        'size' => 135069
    ]
]

$request->body()->file('image');
$request->file('image');    // short approach

// Example output:
[
    'name' => 'image01.jpg',
    'type' => 'image/jpeg',
    'tmp_name' => '\path\to\tmp\php2660.tmp',
    'error' => 0,
    'size' => 135069
]

$request->body()->contentLength();

// Example output:
135467

$request->body()->contentType();

// Example output:
'multipart/form-data; boundary=----WebKitFormBoundarySMTxQwbotazq4ctK'