1. Go to this page and download the library: Download johnvandeweghe/lunixrest 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/ */
johnvandeweghe / lunixrest example snippets
$httpServer = new \LunixREST\HTTPServer($server, $requestFactory, $logger);
$serverRequest = \GuzzleHttp\Psr7\ServerRequest::fromGlobals();
\LunixREST\HTTPServer::dumpResponse($httpServer->handleRequest($serverRequest, new GuzzleHttp\Psr7\Response()));
$server = new GenericServer($accessControl, $throttle, $responseFactory, $router);
$accessControl = new \LunixREST\Server\AccessControl\PublicAccessControl();
$throttle = new \LunixREST\Server\Throttle\NoThrottle();
$responseFactory = new \LunixREST\Server\ResponseFactory\RegisteredResponseFactory([
'application/json' => new \LunixRESTBasics\APIResponse\JSONResponseDataSerializer()
]);
$router = new \LunixREST\Server\Router\GenericRouter($endpointFactory);
$endpointFactory = new \LunixRESTBasics\Endpoint\SingleEndpointFactory(new HelloWorld());
use LunixREST\Server\APIResponse\APIResponseData;
use LunixREST\Server\Router\Endpoint\DefaultEndpoint;
use LunixREST\Server\Router\Endpoint\Exceptions\UnsupportedMethodException;
use LunixREST\Server\APIRequest\APIRequest;
class HelloWorld extends DefaultEndpoint
{
/**
* @param APIRequest $request
* @return APIResponseData
* @throws UnsupportedMethodException
*/
public function getAll(APIRequest $request): APIResponseData
{
return new APIResponseData([
"helloworld" => "HelloWorld"
]);
}
}
$requestFactory = new \LunixRESTBasics\APIRequest\RequestFactory\BasicRequestFactory();
$logger = new \Psr\Log\NullLogger();
$accessControl = new \LunixREST\Server\AccessControl\PublicAccessControl();
$throttle = new \LunixREST\Server\Throttle\NoThrottle();
$responseFactory = new \LunixREST\Server\ResponseFactory\RegisteredResponseFactory([
'application/json' => new \LunixRESTBasics\APIResponse\JSONResponseDataSerializer()
]);
$endpointFactory = new \LunixRESTBasics\Endpoint\SingleEndpointFactory(new \HelloWorld());
$router = new \LunixREST\Server\Router\GenericRouter($endpointFactory);
$server = new \LunixREST\Server\GenericServer($accessControl, $throttle, $responseFactory, $router);
$requestFactory = new \LunixRESTBasics\APIRequest\RequestFactory\BasicRequestFactory\BasicRequestFactory();
$logger = new \Psr\Log\NullLogger();
$httpServer = new \LunixREST\HTTPServer($server, $requestFactory, $logger);
$serverRequest = \GuzzleHttp\Psr7\ServerRequest::fromGlobals();
\LunixREST\HTTPServer::dumpResponse($httpServer->handleRequest($serverRequest, new \GuzzleHttp\Psr7\Response()));
use LunixREST\Server\APIResponse\APIResponseData;
use LunixREST\Server\Router\Endpoint\DefaultEndpoint;
use LunixREST\Server\Router\Endpoint\Exceptions\UnsupportedMethodException;
use LunixREST\Server\APIRequest\APIRequest;
class HelloWorld extends DefaultEndpoint
{
/**
* @param APIRequest $request
* @return APIResponseData
* @throws UnsupportedMethodException
*/
public function getAll(APIRequest $request): APIResponseData
{
return new APIResponseData([
"helloworld" => "HelloWorld"
]);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.