1. Go to this page and download the library: Download malinichevvv/lift-php 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/ */
malinichevvv / lift-php example snippets
Lift\App;
use Lift\Http\Request;
use Lift\Http\Response;
$app = new App();
$app->get('/', fn() => ['message' => 'Hello, World!']);
$app->get('/users/{id:\d+}', function (Request $req) use ($repo) {
$user = $repo->find((int) $req->param('id'));
return $user ?? throw new \Lift\Exception\NotFoundException();
});
$app->post('/users', function (Request $req) use ($repo) {
$data = $req->validate([
'name' => '
use Lift\Debug\ErrorRenderer;
// Content-negotiating handler — JSON for API clients, HTML for browsers
$app->onError(ErrorRenderer::auto());
// Or custom
$app->onException(\Lift\Exception\NotFoundException::class, fn() =>
Response::json(['error' => 'Not found'], 404)
);
use Lift\Testing\TestCase;
final class UserApiTest extends TestCase
{
public function testCreateUser(): void
{
$res = $this->post('/users', ['name' => 'Alice', 'email' => '[email protected]']);
$this->assertStatus(201, $res);
$this->assertJsonContains(['name' => 'Alice'], $res);
}
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.