PHPackages                             yohan/rest-flex-php - 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. yohan/rest-flex-php

ActiveLibrary

yohan/rest-flex-php
===================

RestFlexPHP is a robust PHP package meticulously crafted to simplify the intricacies of handling HTTP requests, with a primary focus on supercharging your experience in managing RESTful APIs. This package provides an elegant and developer-friendly interface, allowing you to effortlessly send requests, handle responses, and navigate RESTful endpoints with finesse. Elevate your PHP-based API interactions with RestFlexPHP and enjoy a seamless development journey.

1.0.8(2y ago)119Apache-2.0PHP

Since Nov 18Pushed 2y ago1 watchersCompare

[ Source](https://github.com/YohanSandun/rest-flex-php)[ Packagist](https://packagist.org/packages/yohan/rest-flex-php)[ RSS](/packages/yohan-rest-flex-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

RestFlexPHP
===========

[](#restflexphp)

[![Total Downloads](https://camo.githubusercontent.com/e1a51f0cf5282d450a56dcc32b4193826f00664b3a196c1bca72334ef9aae3f0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f796f68616e2f726573742d666c65782d7068703f636f6c6f723d726762283330253243323031253243333129)](https://packagist.org/packages/yohan/rest-flex-php)[![Latest Stable Version](https://camo.githubusercontent.com/6c674d6f7785245408e7da63e2242780504fda527b52dd9eaa1a849400404d5e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f796f68616e2f726573742d666c65782d706870)](https://packagist.org/packages/yohan/rest-flex-php)

`RestFlexPHP` is a lightweight PHP package designed to simplify handling RESTful requests and responses. It includes a flexible controller class (`RestFlexController`) for routing requests and a request class (`RestFlexRequest`) for encapsulating request-related data.

Installation
------------

[](#installation)

You can install `RestFlexPHP` using [Composer](https://getcomposer.org/):

```
composer require yohan/rest-flex-php
```

Setting up URL Rewriting
------------------------

[](#setting-up-url-rewriting)

To enable URL rewriting for your RESTful API, you need to create an `.htaccess` file in the same directory as your main logic file (e.g., `index.php`). The file should contain the following mod\_rewrite rules:

```

    RewriteEngine On
    RewriteBase /path-from-the-root/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ ./index.php?url=$1 [QSA,L]

```

Usage
-----

[](#usage)

### RestFlexController

[](#restflexcontroller)

The `RestFlexController` class provides a simple routing mechanism for handling HTTP requests. You can define routes using the get, post, put, and delete methods.

Example:

```

```

Example: Separating different routes with separate classes.

Here's a simple example demonstrating how to use `RestFlexPHP` to create a basic UserController with user-related routes.

#### UserController.php

[](#usercontrollerphp)

```
