PHP code example of williamheelis / restful-inputs

1. Go to this page and download the library: Download williamheelis/restful-inputs 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/ */

    

williamheelis / restful-inputs example snippets


$_RES['debug'] = "bob"

Inputs::extend('debug');
$_RES['debug'] = "bob"

use Restful\Inputs;
Inputs::init();
Inputs::setPath('api/something/{uid}'); //only needed if you actually have a path with params - and it assumes you're in an index.php

$uid = $_PATH['uid'] ?? null;
$name = $_JSON['name'] ?? 'guest';

$_RES['data'] = ['uid' => $uid, 'name' => $name];
$_RES['status_code'] = 200;


use Restful\Inputs;
Inputs::init();

$auth = $_HEADER['Authorization'] ?? null;
$userAgent = $_HEADER['User-Agent'] ?? null;

if (!$auth) {
    $_RES['status_code'] = 401;
    $_RES['data'] = ['error' => 'Missing auth token'];
    exit;
}

{
  "username": "jdoe",
  "email": "[email protected]"
}

use Restful\Inputs;
Inputs::init();

if (Inputs::is('PUT')) {
    $username = $_PUT['username'] ?? null;
    $email = $_PUT['email'] ?? null;

    $_RES['data'] = ['updated' => compact('username', 'email')];
}

use Restful\Inputs;
Inputs::init();

if (!Inputs::is('PUT')) {
    $_RES['status_code'] = 401;
    $_RES['data'] = ['error' => 'not _PUT'];
    //or $_RES['error'] = 'Name is 

use Restful\Inputs;
Inputs::init();

$name = $_JSON['name'] ?? 'guest';

if (!$name) {
    $_RES['status_code'] = 400;
    $_RES['data'] = ['error' => 'Name is 

$_RES['status_code'] = 200;
$_RES['headers']['X-Custom-Header'] = 'Foobar';
$_RES['data'] = ['success' => true];
exit;

$_RES['status_code'] = 404;
$_RES['data'] = ['error' => 'Not found'];
exit;

$_RES['status_code'] = 204;
$_RES['data'] = null; // no body
exit;