lark / app
Lark Application
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
Requires
- lark/framework: ^0.25.0
README
Lark is a modern, lightweight app framework designed specifically for developing REST APIs.
Installation
Create project directory and move to the project directory:
mkdir myapp
cd myapp
Install using composer:
composer create-project lark/app ./
Then, initialize project:
./lark --init
Console
Lark Console is available to assist in creating routes, schemas, models and revisions. Lark Console can be run from the project root directory.
./lark route items
Namespaces can also be used.
./lark route api/items
View all commands with
./lark
or./lark help
View command specific help with./lark help COMMAND
Middleware
Create middleware files in the app/Middleware
directory.
Example middleware class:
namespace App\Middleware; use Lark\Request; use Lark\Response; class UserMiddleware { public function auth(Request $req, Response $res): void { // auth here } }
For this example, the middleware can be setup in app/routes.php
like:
router()->matched([App\Middleware\UserMiddleware::class, "auth"]);
Read the framework docs on middleware.
App Class
#todo docs about app class props + methods
MVC Application
Lark can use controllers that are common in MVC applications. Create controller files in the app/Controller
directory and extend the base App\Controller
class.
Example base controller class app/Controller.php
:
namespace App; use Lark\Response; abstract class Controller { protected Response $res; public function __construct() { $this->res = res(); } }
Example controller class app/Controller/ItemsController.php
:
namespace App\Controller; use App\Model\Item as ItemModel; class ItemsController extends \App\Controller { private ItemModel $model; public function __construct() { $this->model = new ItemModel; } public function get(): void { $this->res->json( $this->model->find() ); } }
For this example, a route can be setup in app/routes.php
like:
router()->get("/items", [App\Controller\ItemsController::class, "get"]);
Read the framework docs on route actions.
Custom Validation Rules
Custom validation rules should be created in the app/Validator
directory like app/Validator/MyRule.php
.
Read the framework docs on custom validation rules.