logadapp/router

PHP Request Router library

v0.0.2 2023-07-13 23:06 UTC

This package is auto-updated.

Last update: 2024-04-21 18:54:34 UTC


README

LogadApp Router is a PHP router class that provides routing capabilities for building web applications.

Table of Contents

Installation

To use LogadApp Router in your PHP project, you can either manually download the source code or install it via Composer.

Composer Installation

You can install LogadApp Router using Composer by running the following command:

composer require logadapp/router

Usage

To start using LogadApp Router, follow these steps:

  1. Include the composer autoload file in your PHP script:

    require_once 'vendor/autoload.php';
  2. Create a new instance of the Router class:

    $router = new LogadApp\Router\Router();
  3. Define routes using the available HTTP methods (GET, POST, PATCH, DELETE) and their respective handler callbacks:

    $router->get('/', function () {
       // Handle GET request for the root path
    });
    
    $router->post('/users', function () {
       // Handle POST request for the /users path
    });
    
    $router->group('/auth', function() use ($router) {
       $router->post('/login', [AuthController::class, 'login']);
    
       $router->post('/register', function () {
           // Handle POST request for the /auth/register path
       });
    }
  4. Run the router to handle incoming requests:

    $router->run();

For more usages, check index.php or the examples folder.

Features

  • Simple and lightweight PHP router
  • Support for common HTTP methods: GET, POST, PATCH, DELETE
  • Route grouping and prefixing
  • Customizable 404 (Not Found) and 405 (Method Not Allowed) handlers
  • Custom route found handlers
  • Integration with classes as callback handlers

Contributing

As always, contributions are welcome!