PHP code example of aalfiann / slim-etag-middleware
1. Go to this page and download the library: Download aalfiann/slim-etag-middleware 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/ */
aalfiann / slim-etag-middleware example snippets
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
use \aalfiann\Slim\Middleware\ETag;
// Initialize Slim App
$app = new \Slim\App($settings);
// create route /
$app->get('/', function (Request $request, Response $response) {
$data = ['title' => 'hello world'];
// create new strong etag. eg: "abc"
return $response
->withHeader('ETag','"abc"')
->withJson($data,200,JSON_PRETTY_PRINT);
})
// this etag middleware will check is current etag same as request etag or not?
// if same then response header will be 304 Not Modified and empty body.
->add(new ETag('abc','strong'))
->setName("/");
$app->run();