Skip to content

peledies/php-micro-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

PHP Micro Router

This router is a super slim router that does not have any package requirements. It gives a very similar look and feel as the Laravel and Lumen routers but without all the unnecesary cruft.

It supports the following:

  • get requests
  • post requests
  • put requests
  • delete requests
  • URL parameterization

Rewirite engine required

In your production environment you will want apache or nginx to rewrite the urls for you so they look pretty.

When developing locally, you can skip this step

Add the following to your .htaccess file

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)$ index.php [NC,L]

Local development

The following command will start a php server and point it to your example.php file.

All urls will be demoed in the following format http://localhost:8000/api/example

php -S localhost:8000 example.php

Usage

Require the router class in your php file

require(__DIR__."/class.router.php");

Create a new instance of the router

$router = new Router();

Add routes to the router

$router->get('/api/example','example_one');
$router->get('/api/example/{id}','example_two');

Start the router

$router->start();

See the example.php file for additonal examples

About

A very simple router for creating a basic REST API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages