PHPackages                             digitalastronauts/rocket - 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. digitalastronauts/rocket

ActiveLibrary[API Development](/categories/api)

digitalastronauts/rocket
========================

API mapping implementation.

02PHP

Since Nov 28Pushed 4y agoCompare

[ Source](https://github.com/DigitalAstronauts/rocket)[ Packagist](https://packagist.org/packages/digitalastronauts/rocket)[ RSS](/packages/digitalastronauts-rocket/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Rocket
======

[](#rocket)

This project should make building API easy as possible. We are using attribute mapping to entities to build easily structure that can help you implement your application router within few minutes.

Usage
-----

[](#usage)

Let's imagine that we have some simple entities which represents our domain:

```
class Author {
    public int $id;
    public string $name;
    public iterable $books;
}

class Book {
    public int $id;
    public string $name;
    public string $isbn;
}
```

We want to build easy routing for this entities. With `Rocket` you should enrich those entities into:

```
#[\Rocket\Mapping\Resource(path: "/authors")]
class Author {
    #[\Rocket\Mapping\Id]
    #[\Rocket\Mapping\SubResource]
    public int $id;
    public string $name;
    #[\Rocket\Mapping\SubResource(path: "books")]
    public iterable $books;
}

#[
    \Rocket\Mapping\Resource(method: 'GET', path: "/books", handler: 'YourRetrieveController'),
    \Rocket\Mapping\Resource(method: 'POST', path: "/books", handler: 'YourCreateClass', middlewares: ['ProtectWriteMiddleware']),
]
class Book {
    #[\Rocket\Mapping\Id]
    #[
        \Rocket\Mapping\SubResource(method: 'GET'),
        \Rocket\Mapping\SubResource(method: 'PUT', middlewares: ['ProtectWriteMiddleware']),
        \Rocket\Mapping\SubResource(method: 'DELETE', middlewares: ['ProtectWriteMiddleware']),
    ]
    public int $id;
    public string $name;
    public string $isbn;
}
```

With this definition you can build this routing table:

MethodUrl pathHandler`*``/authors``null``*``/authors/{id}``null``*``/authors/{id}/books``null``GET``/books``null``POST``/books``null``GET``/books/{id}``null``PUT``/books/{id}``null``DELETE``/books/{id}``null`With this definition you can use `MappingFactory` to get resource collection.

```
$resourceCollection = (new \Rocket\MappingFactory)->create(
    'directory of entities/resources',
    'class namespace prefix - e.g. \App\Entity'
);
```

With this collection you can easily build your API router. I will show you usage with `league/route` that is used for [integration testing](./tests/MappingFactoryTest.php).

```
use Laminas\Diactoros\Response\JsonResponse;
use Laminas\Diactoros\ServerRequest;
use League\Route\Router;
use Rocket\MappingFactory;

function createRouter(): Router {
    $factory = new MappingFactory();
    $resourceCollections = $factory->create(
        __DIR__ . '/Fixture/Resource',
        'Rocket\Tests\Fixture\Resource'
    );

    $router = new Router();
    $handler = fn(ServerRequest $request) => new JsonResponse(['ok' => true]);
    foreach ($resourceCollections as $collection) {
        foreach ($collection->getResourceList() as $resource) {
            $route = $router->map(
                $resource->method,
                $resource->path,
                $handler
            );
            foreach ($resource->middlewares as $middleware) {
                $route->middleware(new $middleware());
            }
        }
        foreach ($collection->getSubResourceList() as $subResource) {
            $route = $router->map(
                $subResource->method,
                sprintf('%s/{%s}/%s', $subResource->parentPath, $collection->getId()->name, $subResource->path),
                $handler
            );
            foreach ($subResource->middlewares as $middleware) {
                $route->middleware(new $middleware());
            }
        }
    }
    return $router;
}
```

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![mnohosten](https://avatars.githubusercontent.com/u/4037114?v=4)](https://github.com/mnohosten "mnohosten (3 commits)")

### Embed Badge

![Health badge](/badges/digitalastronauts-rocket/health.svg)

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

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M20](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k13](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

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