Slim Framework based simple helper to generate RESTful API's and applications, requires PHP 7.
KAPI means "door" in Turkish.
git clone https://github.com/emir/kapi myproject
cd myproject
composer install
It will create an example project.
$EDITOR .env
phinx migrate
cd myproject
php -S localhost:8080 -t public
That's all! :)
You should define your URLs in routes.php:
# src/routes.php
<?php
$urls = [
['get', '/books', 'BooksController::index', 'List all books.']
];
Create your models:
# src/Models/Book.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Book extends Model
{
/**
* @var array
*/
protected $guarded = [];
}
Create your Controllers and methods:
# src/Controllers/BooksController.php
<?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);
}
}
Done!