PHP code example of benycode / psr-response-renderer

1. Go to this page and download the library: Download benycode/psr-response-renderer 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/ */

    

benycode / psr-response-renderer example snippets



use Psr\Http\Message\ResponseInterface;

	....
	public function __construct(
        private readonly JsonRenderer $renderer,
    ) {
    }
	....
	
	public function __invoke(
        ServerRequestInterface $request,
        ResponseInterface $response,
    ): ResponseInterface {
		return $this->renderer
            ->response($response)
            ->create([
                'message' => 'created',
            ])
            ->withStatus(StatusCodeInterface::STATUS_CREATED)
        ;
	}