PHP code example of sohris / http

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

    

sohris / http example snippets


namespace App\Routes\Template;

use Sohris\Http\Response;
use Sohris\Http\Router\RouterControllers\DRMRouter;
use Sohris\Http\Annotations\SessionJWT;
use Sohris\Http\Annotations\Needed;
use Sohris\Http\Annotations\HttpMethod;
use Sohris\Http\Annotations\Route;

class Teste extends DRMRouter
{
    /**
     * @Route("/template/teste/requisicao_1")
     * @SessionJWT(true)
     * @HttpMethod("POST")
     * @Needed({"param_1", "param_2"})
     */
    public static function requisicao_1(\Psr\Http\Message\RequestInterface $request)
    {        
        return Response::Json("Hello World!");
    }
}

use React\Promise\Promise;

public static function asyncRoute(\Psr\Http\Message\RequestInterface $request)
{
    return new Promise(function ($resolve) {
        // Simulate an asynchronous operation
        $resolve(Response::Json( "Async Response"));
    });
}

@Needed({"param_1", "param_2"})

public static function rota_1(\Psr\Http\Message\RequestInterface $request)
{
    echo $request->REQUEST['param_1'];
    echo $request->REQUEST['param_2'];
}

@HttpMethod("POST")