Skip to content

aalfiann/slim-etag-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Slim ETag Middleware

Version Downloads License

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.

About

ETag middleware for Slim Framework 3

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages