Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Demonstrates a simple Slim app with routes for listing and creating items, using minimal setup.
<?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();
// Sample in-memory data
$items = [];
$app->get('/items', function (Request $request, Response $response) use (&$items) {
$response->getBody()->write(json_encode($items));
return $response->withHeader('Content-Type', 'application/json');
});
$app->post('/items', function (Request $request, Response $response) use (&$items) {
$data = json_decode($request->getBody(), true);
$items[] = $data;
$response->getBody()->write(json_encode($data));
return $response->withHeader('Content-Type', 'application/json');
});
$app->run();Slim is a lightweight PHP micro-framework designed for quickly building simple yet powerful web applications and APIs. It focuses on minimalism, flexibility, and performance, giving developers full control over application architecture without imposing heavy conventions.
Origin & Creator
Created by Josh Lockhart in 2010, Slim was designed to be a fast, minimalistic framework for PHP developers who needed flexibility without unnecessary overhead.
Industrial Note
Slim is often chosen by startups, microservices developers, and API-first teams who want a minimalistic yet PSR-compliant framework without the weight of full-stack frameworks.