PHP code example of fast-forward / http-factory
1. Go to this page and download the library: Download fast-forward/http-factory 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/ */
fast-forward / http-factory example snippets
use FastForward\Container\container;
use FastForward\Config\ArrayConfig;
use FastForward\Container\ContainerInterface;
$config = new ArrayConfig([
ContainerInterface::class => [
// Reference the service provider by class name
HttpMessageFactoryServiceProvider::class,
],
]);
$container = container($config);
$requestFactory = $container->get(Psr\Http\Message\RequestFactoryInterface::class);
$serverRequest = $container->get(Psr\Http\Message\ServerRequestInterface::class);
$responseFactory = $container->get(FastForward\Http\Message\Factory\ResponseFactoryInterface::class);
$streamFactory = $container->get(FastForward\Http\Message\Factory\StreamFactoryInterface::class);
$request = $requestFactory->createRequest('GET', '/health');
$jsonResponse = $responseFactory->createResponseFromPayload(['ok' => true]);
$htmlResponse = $responseFactory->createResponseFromHtml('<h1>Hello</h1>');
$redirectResponse = $responseFactory->createResponseRedirect('/login');
$noContentResponse = $responseFactory->createResponseNoContent();
$acceptedResponse = $responseFactory
->createResponse(202)
->withHeader('Content-Type', 'application/json; charset=utf-8')
->withBody($streamFactory->createStreamFromPayload(['queued' => true]));