aalfiann / slim-etag-middleware
ETag Middleware for Slim Framework 3.
1.0.1
2019-05-10 02:02 UTC
Requires
- php: >=5.5
- slim/slim: ^3.1
This package is auto-updated.
Last update: 2024-12-10 14:15:24 UTC
README
ETag Middleware for Slim Framework 3.
Installation
Install this package via Composer.
composer require "aalfiann/slim-etag-middleware:^1.0"
Usage Example
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();
Note
This etag middleware are used in my project >> Slim API Skeleton.