PHPackages                             fastrest/framework - 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. [API Development](/categories/api)
4. /
5. fastrest/framework

ActiveProject[API Development](/categories/api)

fastrest/framework
==================

A lightweight, PSR-compliant PHP REST framework

v2.x-dev(4mo ago)13MITPHPPHP &gt;=8.1CI passing

Since Feb 19Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/zainaftab44/FastREST)[ Packagist](https://packagist.org/packages/fastrest/framework)[ RSS](/packages/fastrest-framework/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (12)Versions (2)Used By (0)

FastREST v2
===========

[](#fastrest-v2)

> The fastest way to build PHP REST APIs — now PSR-compliant, secure, and production-ready.

FastREST started as a zero-learning-curve PHP framework: drop in a controller, name a method, get a route. No config, no boilerplate, no framework tax. That spirit is unchanged in v2.

---

Requirements
------------

[](#requirements)

- **PHP 8.4+** (Uses latest language features and optimizations)
- **Composer** (For dependency management)

What *is* changed is everything underneath. v2 is built on the PHP standard interfaces (PSR-3, 4, 7, 11, 15) so every component — the logger, the HTTP layer, the container — can be swapped for any compatible package without touching your business logic. The original bugs that caused silent data corruption are fixed. Routes are HTTP-verb-aware. Credentials live in `.env`. Controllers are testable.

---

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

[](#table-of-contents)

- [Quick Start](#quick-start)
- [Core Concepts](#core-concepts)
- [Routing](#routing)
- [Controllers](#controllers)
- [Database](#database)
- [QueryBuilder](#querybuilder)
- [Middleware](#middleware)
- [Dependency Injection](#dependency-injection)
- [Logging](#logging)
- [HTTP Client](#http-client)
- [OAuth 1.0](#oauth-10)
- [HTTP Responses &amp; Error Handling](#http-responses--error-handling)
- [Replacing / Swapping Modules](#replacing--swapping-modules)
- [Configuration](#configuration)
- [Testing](#testing)
- [Migrating from v1](#migrating-from-v1)
- [Project Structure](#project-structure)

---

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

[](#installation)

### 1. Using Composer (Recommended)

[](#1-using-composer-recommended)

You can create a new project skeleton using the following command:

```
composer create-project fastrest/framework [project-name]
```

This will:

- Download the framework and dependencies.
- Copy `.env.example` to `.env`.
- Set up the project structure.

### 2. Manual Installation

[](#2-manual-installation)

```
git clone https://github.com/fastrest/framework.git [project-name]
cd [project-name]
composer install
```

---

Quick Start
-----------

[](#quick-start)

```
# 1. Set up environment
cp .env.example .env

# 2. Serve locally
php -S localhost:8000 public/index.php

# 3. Run tests
composer test
```

Point a production web server's document root at `/public`. Everything above `/public` is private.

**Nginx example:**

```
root /var/www/fastrest/public;
location / {
    try_files $uri $uri/ /index.php?$query_string;
}
```

---

Core Concepts
-------------

[](#core-concepts)

FastREST v2 is built on five PHP standard interfaces. You never depend on a concrete implementation — only on the interface. This means every layer is replaceable.

StandardWhat it doesDefault implementation**PSR-4**AutoloadingComposer**PSR-3**LoggingMonolog**PSR-7**HTTP request &amp; response objectsNyholm/PSR-7**PSR-11**Dependency injection containerPHP-DI**PSR-15**Middleware pipelineCustom (ships with framework)---

Routing
-------

[](#routing)

Routes are defined explicitly in `config/routes.php`. Each route maps an HTTP verb and a URI pattern to a controller method.

```
// config/routes.php
return static function (Router $router): void {

    $router->get('/products',          [ProductController::class, 'index']);
    $router->get('/products/{id}',     [ProductController::class, 'show']);
    $router->post('/products',         [ProductController::class, 'store']);
    $router->put('/products/{id}',     [ProductController::class, 'update']);
    $router->delete('/products/{id}',  [ProductController::class, 'destroy']);

};
```

### Route parameters

[](#route-parameters)

Segments wrapped in `{braces}` are captured and injected into the request as attributes:

```
// Route: GET /products/{id}
public function show(ServerRequestInterface $request): ResponseInterface
{
    $id = $request->getAttribute('id'); // "42"
    ...
}
```

### Wrong method → 405

[](#wrong-method--405)

If a URI matches but the HTTP method doesn't, the framework automatically returns `405 Method Not Allowed` with an `Allow` header listing what's accepted. You don't write any of that code.

### Catch-all

[](#catch-all)

```
$router->any('/health', [HealthController::class, 'check']);
```

---

Controllers
-----------

[](#controllers)

Controllers are plain PHP classes. There are no base classes to extend, no interfaces to implement. Dependencies go in the constructor — the DI container provides them automatically.

```
