1. Go to this page and download the library: Download esase/tiny-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/ */
esase / tiny-http example snippets
use Tiny\Http\Request;
use Tiny\Http\RequestCliParams;
use Tiny\Http\RequestHttpParams;
$request = new Request((php_sapi_name() === 'cli'
? new RequestCliParams($_SERVER)
: new RequestHttpParams($_SERVER)
));
echo $request->getRequest(); // prints the `files/import` or `import files` for the CLI mode
echo $request->getMethod(); // prints `GET`, `POST`, `CONSOLE`, etc
use Tiny\Http\ResponseCli;
use Tiny\Http\ResponseHttp;
use Tiny\Http\ResponseHttpUtils;
$response = (php_sapi_name() === 'cli'
? new ResponseCli()
: new ResponseHttp(
new ResponseHttpUtils()
);
$response
->setCode(201)
->setResponse('{"name": "test"}')
->setResponseType('application/json');
// we don't care about neither "CLI" nor "HTTP", we just print the value
echo $response->getResponseForDisplaying();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.