1. Go to this page and download the library: Download adil-jaafar/picophp 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/ */
adil-jaafar / picophp example snippets
// app/foo/bar/routes.php
$get = function(Request $request, Response $response) {
$data = ['message' => 'Hello from /foo/bar'];
return $response(200)->json($data);
};
$post = function(Request $request, Response $response) {
$body = $request->body();
// Process the POST data
return $response(201)->json(['message' => 'Resource created', 'data' => $body]);
};
// app/users/[id]/edit/routes.php
$get = function(Path $path, Response $response) {
$user_id = $path['id']; // Access the "id" parameter from the URL
// Fetch user data based on $user_id
// ...
return $response(200)->json(['user_id' => $user_id, /* ... */]);
};
// app/photo/[...chemin]/routes.php
$get = function(Path $path, Response $response) {
$photo_path = $path['chemin']; // Access the "chemin" parameter from the URL which can contain multiple segments
// Ex: /photo/path/to/my/image.jpg
// $photo_path will be equal to "path/to/my/image.jpg"
// Serve the image at $photo_path
// ...
return $response(200); // Or any other response
};