PHP code example of emir / kapi

1. Go to this page and download the library: Download emir/kapi 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/ */

    

emir / kapi example snippets


# src/routes.php


$urls = [
  ['get', '/books', 'BooksController::index', 'List all books.']
];

# src/Models/Book.php


namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Book extends Model
{
    /**
     * @var array
     */
    protected $guarded = [];
}

# src/Controllers/BooksController.php


namespace App\Controllers;

use App\Models\Book;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Database\QueryException;
use Slim\Http\Request;
use Slim\Http\Response;

class BooksController extends AbstractController
{
    /**
     * @param Request $request
     * @param Response $response
     * @return Response
     */
    public function index(Request $request, Response $response): Response
    {
        $books = Book::all();
        
        return $response->withJson($books);
    }
}