PHPackages                             sectoroverload2k/rest-router - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. sectoroverload2k/rest-router

ActiveLibrary[HTTP &amp; Networking](/categories/http)

sectoroverload2k/rest-router
============================

PHP Library for REST API

1.1.9(2mo ago)0336↓50%1MITPHPPHP &gt;=8.0.0

Since Jul 11Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/sectoroverload2k/rest-router)[ Packagist](https://packagist.org/packages/sectoroverload2k/rest-router)[ RSS](/packages/sectoroverload2k-rest-router/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (16)Used By (1)

REST Router for PHP
===================

[](#rest-router-for-php)

This code provides the basic framework for a PHP developer that wants to build a REST service.

Some of the features provided in this framework are:

- Multiple request methods (GET, POST, PUT, DELETE)
- Custom URL routing to support variables
- Automatic method name resolution based on HTTP verbs

Table of Contents
-----------------

[](#table-of-contents)

1. [Basic Routing](#basic-routing)
2. [Controller Structure](#controller-structure)
3. [Automatic Route Resolution](#automatic-route-resolution)
4. [Custom Routes](#custom-routes)
5. [Route Parameters](#route-parameters)
6. [Best Practices](#best-practices)

---

Basic Routing
-------------

[](#basic-routing)

### URL Structure

[](#url-structure)

```
/controller/action

```

Example Request: `GET /users/profile`

- Default controller is **index**
- Default action is **index**

### How the Router Works

[](#how-the-router-works)

The REST Router will:

1. Parse the incoming request URL
2. Load the appropriate controller file from the `/controllers` directory
3. Instantiate the controller class
4. Call the appropriate method based on HTTP verb + action

---

Controller Structure
--------------------

[](#controller-structure)

### File Naming Convention

[](#file-naming-convention)

Controllers should follow your application's naming convention. Common patterns:

- `/controllers/c_users.php` (with prefix)

### Class Example

[](#class-example)

```
