Don’t have Composer? It’s easy to install by following the instructions on their download page.
We recommend you install Slim with Composer.
Navigate into your project’s root directory and execute the bash command
shown below. This command downloads the Slim Framework and its third-party
dependencies into your project’s vendor/
directory.
composer require slim/slim:4.0.0
Before you can get up and running with Slim you will need to choose a PSR-7 implementation that best fits your application.
In order for auto-detection to work and enable you to use AppFactory::create()
and App::run()
without having to manually create a ServerRequest
you need to install one of the following implementations:
composer require slim/psr7
composer require nyholm/psr7 nyholm/psr7-server
composer require guzzlehttp/psr7 http-interop/http-factory-guzzle
composer require zendframework/zend-diactoros
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
require __DIR__ . '/../vendor/autoload.php';
$app = AppFactory::create();
$app->get('/', function (Request $request, Response $response, $args) {
$response->getBody()->write("Hello world!");
return $response;
});
$app->run();