PHPackages                             developer-programming-2023/simple-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. developer-programming-2023/simple-router

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

developer-programming-2023/simple-router
========================================

A simple and lightweight PHP router for handling HTTP requests.

v1.0.0(4mo ago)02MITPHPPHP &gt;=8.0

Since Feb 23Pushed 4mo agoCompare

[ Source](https://github.com/Developer-Programming-2023/simple-router)[ Packagist](https://packagist.org/packages/developer-programming-2023/simple-router)[ RSS](/packages/developer-programming-2023-simple-router/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

Simple Router
=============

[](#simple-router)

> A simple and lightweight PHP router for handling HTTP requests. (Một PHP Router đơn giản và nhẹ để xử lý các HTTP request.)

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/f9a61eee600abfa4c06628ff826dc6a7dfffc0cceca828fd79751b43e44f451f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344382e302d626c75652e737667)](https://php.net)

---

📋 Mục lục
---------

[](#-mục-lục)

- [Giới thiệu](#-gi%E1%BB%9Bi-thi%E1%BB%87u)
- [Yêu cầu hệ thống](#-y%C3%AAu-c%E1%BA%A7u-h%E1%BB%87-th%E1%BB%91ng)
- [Cài đặt](#-c%C3%A0i-%C4%91%E1%BA%B7t)
- [Cách sử dụng](#-c%C3%A1ch-s%E1%BB%AD-d%E1%BB%A5ng)
- [HTTP Methods](#-http-methods-%C4%91%C6%B0%E1%BB%A3c-h%E1%BB%97-tr%E1%BB%A3)
- [Cấu trúc dự án](#-c%E1%BA%A5u-tr%C3%BAc-d%E1%BB%B1-%C3%A1n)
- [Thứ tự tạo file](#-th%E1%BB%A9-t%E1%BB%B1-t%E1%BA%A1o-file-khi-l%C3%A0m-package)
- [Cách publish lên Packagist](#-c%C3%A1ch-publish-l%C3%AAn-packagist)
- [License](#-license)

---

🎯 Giới thiệu
------------

[](#-giới-thiệu)

**Simple Router** là một PHP package giúp bạn định tuyến (routing) các HTTP request một cách đơn giản.

**Routing là gì?**

- Khi người dùng truy cập `/test` → chạy code xử lý trang test
- Khi người dùng truy cập `/hello` → chạy code xử lý trang hello
- Không cần tạo thư mục/file thật cho mỗi đường dẫn

**Tại sao dùng package này?**

- ✅ Nhẹ, không phụ thuộc thư viện khác
- ✅ Hỗ trợ tất cả HTTP methods: GET, POST, PUT, PATCH, DELETE
- ✅ 3 cách xử lý route: Closure, Named Function, File PHP
- ✅ Dễ cài đặt qua Composer

---

💻 Yêu cầu hệ thống
------------------

[](#-yêu-cầu-hệ-thống)

Yêu cầuPhiên bảnPHP&gt;= 8.0Composer&gt;= 2.0---

📦 Cài đặt
---------

[](#-cài-đặt)

### Cách 1: Cài qua Composer (khuyến nghị)

[](#cách-1-cài-qua-composer-khuyến-nghị)

```
composer require developer-programming-2023/simple-router
```

### Cách 2: Clone từ GitHub

[](#cách-2-clone-từ-github)

```
git clone https://github.com/Developer-Programming-2023/simple-router.git
cd simple-router
composer install
```

---

🚀 Cách sử dụng
--------------

[](#-cách-sử-dụng)

### Bước 1: Tạo file `index.php`

[](#bước-1-tạo-file-indexphp)

```
