leafs/router

Leaf router module for Leaf PHP.

v0.1.4 2021-11-22 09:27 UTC

This package is auto-updated.

Last update: 2021-11-22 16:18:39 UTC


README



68747470733a2f2f6c6561667068702e6e65746c6966792e6170702f6173736574732f696d672f6c656166332d6c6f676f2e706e67

Leaf Router Module



Leaf Router

Latest Stable Version Total Downloads License

Leaf router is the core routing engine which powers the Leaf PHP framework. Leaf router is now served as a serve-yourself module which can even be used outside the Leaf ecosystem.

Leaf Router is still built into Leaf Core and doesn't need to be installed separately.

Installation

You can easily install Leaf using Composer.

composer require leafs/router

Basic Usage

If you are using leaf router with Leaf, you can build your leaf apps just as you've always done:

<?php
require __DIR__ . "vendor/autoload.php";

// GET example
app()->get("/", function () {
  response()->json([
    "message" => "Welcome!"
  ]);
});

// MATCH example
app()->match("GET", "/test", function () {
  response()->json([
    "message" => "Test!"
  ]);
});

app()->run();

If however, you are using leaf router outside of the leaf framework, you simply need to call these methods on the Leaf\Router object:

<?php

use Leaf\Router;

require __DIR__ . "vendor/autoload.php";

// GET example
Router::get("/", function () {
  echo json_encode([
    "message" => "Welcome!"
  ]);
});

// MATCH example
Router::match("GET", "/test", function () {
  echo json_encode([
    "message" => "Test!"
  ]);
});

Router::run();

You may quickly test this using the built-in PHP server:

php -S localhost:8000

View temporary docs here

Built with ❤ by Mychi Darko