PHPackages                             nddcoder/rest - 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. [Framework](/categories/framework)
4. /
5. nddcoder/rest

ActiveProject[Framework](/categories/framework)

nddcoder/rest
=============

The Rest Framework.

0.0.3(4y ago)07MITShellPHP ^8.0

Since Nov 20Pushed 4y ago2 watchersCompare

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

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

rest-framework
==============

[](#rest-framework)

Rest Framework - PHP Framework for ReactPHP Library

Docs
----

[](#docs)

- [Installation](#installation)
    - [Server Requirements](#server-requirements)
    - [Installing Rest](#installing-rest)
    - [Local Development Server](#local-development-server)
- [Deploy](#deploy)
    - [Using Docker](#using-docker)
    - [Using Supervisor](#using-supervisor)
- [Usage](#usage)
    - [Router](#router)
    - [Dependency Injection](#dependency-injection)
        - [Singleton](#singleton)
        - [Resolve an instance from container](#resolve-from-container)
    - [Helpers](#helpers)

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

[](#installation)

### Server Requirements

[](#server-requirements)

The Rest framework has a few system requirements.

- PHP &gt;= 7.4
- BCMath PHP Extension
- Ctype PHP Extension
- Fileinfo PHP Extension
- JSON PHP Extension
- Mbstring PHP Extension
- OpenSSL PHP Extension
- PDO PHP Extension
- Tokenizer PHP Extension
- XML PHP Extension

### Installing Rest

[](#installing-rest)

Rest utilizes [Composer](https://getcomposer.org) to manage its dependencies. So, before using Rest, make sure you have Composer installed on your machine.

Install Rest by issuing the Composer `create-project` command in your terminal:

```
composer create-project --prefer-dist nddcoder/rest blog

```

### Local Development Server

[](#local-development-server)

Just run `index.php` file

```
php index.php

```

Or, if you have nodemon installed, you can have auto reload feature by using nodemon

```
nodemon index.php

```

Deploy
------

[](#deploy)

### Using Docker

[](#using-docker)

Just build image based on project's `Dockerfile`

```
docker build -t : .
docker run -d \
           -p 8080:8080 \
           -e APP_PORT="0.0.0.0:8080" \
           :

```

### Using Supervisor

[](#using-supervisor)

```
[program:app-name]
process_name=%(program_name)s_%(process_num)02d
command=php /paht/to/project/index.php
autostart=true
autorestart=true

```

Usage
-----

[](#usage)

### Router

[](#router)

Rest using [Fast Route](https://github.com/nikic/FastRoute) for routing. Application routes can be register in `app/Router.php`.

```
class Router extends BaseRouter
{
    protected function register(RouteCollector $routes): void
    {
        $routes->get('/', HomeController::class); //using invokeable controller
        $routes->get('/home', [HomeController::class, 'home']);
        $routes->get('/hello/{name}', [HomeController::class, 'hello']);

        /*
        $routes->post(...)
        $routes->put(...)
        $routes->delete(...)
        */
    }
}
```

### Controller

[](#controller)

The first parameter of controller method always is `ServerRequestInterface`, any route params will following this.

```
class HomeController
{
    public function __invoke(ServerRequestInterface $request)
    {
        $frameworkVersion = Application::VERSION;
        return view('home.twig', compact('frameworkVersion'));
    }

    public function home()
    {
        return response()->redirect('/');
    }

    public function hello(ServerRequestInterface $request, $name)
    {
        return "Hello $name";
    }
}
```

### Dependency Injection

[](#dependency-injection)

Bind class to container

```
Application::getInstance()
    ->onBoot(function (Application $app) {
        $app->bind(ProductServiceInterface::class, fn($app) => new ProductServiceImpl());
    });
```

#### Singleton

[](#singleton)

To make a class is singleton, you can make class implemnt `Singleton` interface or bind to container using `singleton` method

```
use Rest\Contracts\Singleton;

class SlackService extends Singleton {

}

//or

Application::getInstance()
    ->onBoot(function (Application $app) {
        $app->singleton(SlackService::class, SlackService::class);
    });
```

#### Resolve an instance from container

[](#resolve-an-instance-from-container)

Inject dependencies in `__construct` function

```
class ProductController
{
    protected ProductServiceInterface $productService;

    public function __construct(ProductServiceInterface $service)
    {
        $this->productService = $service;
    }
}
```

Using `app` helper

Inject dependencies in `__construct` function

```
class ProductController
{
    public function __construct()
    {
        $this->productService = app(ProductServiceInterface::class);
        //or
        $this->productService = app()->make(ProductServiceInterface::class);
    }
}
```

### Helpers

[](#helpers)

`app`: return Application instance or resolve an instance from container

```
$application = app(); //return Application instance
$classInstance = app(ClassName::class); //ClassName instance
```

`view`: return `ViewResponse` instance. Accept view name and optional data need pass to view

```
class ProductController
{
    public function index()
    {
        $products = [
            //...
        ];

        return view('products.index', [
            'products' => $products
        ]);
    }
}
```

`response`: return `Response` instance, use to build response

```
class ProductController
{
    public function index()
    {
        $products = [
            //...
        ];

        return response()->json([
           'data' => $products
        ]);
    }
}
```

`env`: get enviroment vairable from `$_ENV`. Rest using `vlucas/phpdotenv` for load env variables from `.env` file.

```
$debug = env('APP_DEBUG') == 'true';
```

`dd`: `var_dump and die` variable for debugging.

```
dd($var1, $var2, $var3);
```

`abort`: intermediately return http response. Accept `status code` and `message`

```
abort(500);
abort(403, 'Permission Denied');
```

`abort_if`: `abort` based on `$condition`

```
abort_if($condition, $status, $messagge);
```

`abort_unless`: reversed side of `abort_if`

```
abort_unless($condition, $status, $messagge);
```

`logger`: log a string or an `Throwable` instance to console

```
logger('Error occurred');
logger($exeption);
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~141 days

Total

3

Last Release

1722d ago

PHP version history (2 changes)0.0.1PHP ^7.4|^8.0

0.0.3PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/108944439?v=4)[nddzee](/maintainers/nddcoder)[@nddcoder](https://github.com/nddcoder)

---

Top Contributors

[![dangdungcntt](https://avatars.githubusercontent.com/u/22521948?v=4)](https://github.com/dangdungcntt "dangdungcntt (48 commits)")

---

Tags

frameworkrest

### Embed Badge

![Health badge](/badges/nddcoder-rest/health.svg)

```
[![Health](https://phpackages.com/badges/nddcoder-rest/health.svg)](https://phpackages.com/packages/nddcoder-rest)
```

###  Alternatives

[gotzmann/comet

Modern PHP framework for building blazing fast REST APIs and microservices

68816.2k1](/packages/gotzmann-comet)[phprest/phprest

PHP Rest Framework.

3049.3k](/packages/phprest-phprest)[psx/psx

PHP REST API Framework

17112.6k3](/packages/psx-psx)[podcastcrawler/podcastcrawler

PHP library to find podcasts

402.7k1](/packages/podcastcrawler-podcastcrawler)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
