PHPackages                             danielgsims/php-siren - 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. danielgsims/php-siren

ActiveLibrary[API Development](/categories/api)

danielgsims/php-siren
=====================

Helper to write Siren hypermedia responses

0.9(11y ago)11111MITPHP

Since May 18Pushed 10y agoCompare

[ Source](https://github.com/danielgsims/php-siren)[ Packagist](https://packagist.org/packages/danielgsims/php-siren)[ RSS](/packages/danielgsims-php-siren/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)DependenciesVersions (5)Used By (1)

\#Siren#

"Siren is a hypermedia specification for representing entities. As HTML is used for visually representing documents on a Web site, Siren is a specification for presenting entities via a Web API."

You can read more about Siren and see examples at the [official github repo](https://github.com/kevinswiber/siren)

\#PHP-Siren#

This library is designed to help create valid Siren responses for your Hypermedia API with an object oriented approach. The PHP Siren library consists of components which represent the data structures in Siren (entities, links, actions, fields) and an Encoder which serializes these structures into Siren+JSON.

\#What PHP Siren does not cover#

This library only helps to create the response body. The other asspects of the HTTP Response, such as headers, are outside of the scope of this library.

\#Example

```
    $order = new Entity();
    $order->addClass("order")
           ->setProperties(array(
                "orderNumber" => 42,
                "itemCount" => 3,
                "status" => "pending"
            ));

    $items = new Entity;
    $items->addClass("items")
          ->addClass("collection")
          ->addRel("http://x.io/rels/order-items")
          ->setHref("http://api.x.io/orders/42/items");

    $order->addEntity($items);

    $customerInfo = new Entity;
    $customerInfo->addClass("info")
                 ->addClass("customer")
                 ->addRel("http://x.io/rels/customer")
                 ->setHref("http://api.x.io/customer")
                 ->setProperties(array(
                    "customerId" => "pj123",
                    "name" => "Peter Joseph"
                 ));

    $link = new Link;
    $link->addRel("self")
         ->setHref("http://api.x.io/customers/pj123");

    $customerInfo->addLink($link);

    $order->addEntity($customerInfo);

    $orderNumber = new Field;
    $orderNumber->setName("orderNumber")
                ->setType("hidden")
                ->setValue(42);

    $productCode = new Field;
    $productCode->setName("productCode");

    $quantity = new Field;
    $quantity->setName("quantity")
             ->setType("number");

    $action = new Action;
    $action->setName("add-item")
        ->setHref("http://api.x.io/orders/42/items")
        ->setMethod("POST")
        ->setTitle("Add Item")
        ->addField($orderNumber)
        ->addField($productCode)
        ->addField($quantity);

    $order->addAction($action);

    $self = new Link;
    $self->addRel("self")
         ->setHref("http://api.x.io/orders/42");

    $prev = new Link;
    $prev->addRel("previous")
         ->setHref("http://api.x.io/orders/41");

    $next = new Link;
    $next->addRel("next")
        ->setHref( "http://api.x.io/orders/43");

    $order->addLink($self);
    $order->addLink($prev);
    $order->addLink($next);

    $response = (new Encoder)->encode($order);

    print_r(json_encode($response, JSON_UNESCAPED_SLASHES));

```

Example output

```
{
    "class": [
        "order"
    ],
    "properties": {
        "orderNumber": 42,
        "itemCount": 3,
        "status": "pending"
    },
    "entities": [
        {
            "href": "http://api.x.io/orders/42/items",
            "rel": [
                "http://x.io/rels/order-items"
            ],
            "class": [
                "items",
                "collection"
            ]
        },
        {
            "href": "http://api.x.io/customer",
            "rel": [
                "http://x.io/rels/customer"
            ],
            "class": [
                "info",
                "customer"
            ],
            "properties": {
                "customerId": "pj123",
                "name": "Peter Joseph"
            },
            "links": [
                {
                    "rel": [
                        "self"
                    ],
                    "href": "http://api.x.io/customers/pj123"
                }
            ]
        }
    ],
    "actions": [
        {
            "name": "add-item",
            "href": "http://api.x.io/orders/42/items",
            "method": "POST",
            "title": "Add Item",
            "type": "application/x-www-form-urlencoded",
            "fields": [
                {
                    "name": "orderNumber",
                    "type": "hidden",
                    "value": "42"
                },
                {
                    "name": "productCode",
                    "type": "text"
                },
                {
                    "name": "quantity",
                    "type": "number"
                }
            ]
        }
    ],
    "links": [
        {
            "rel": [
                "self"
            ],
            "href": "http://api.x.io/orders/42"
        },
        {
            "rel": [
                "previous"
            ],
            "href": "http://api.x.io/orders/41"
        },
        {
            "rel": [
                "next"
            ],
            "href": "http://api.x.io/orders/43"
        }
    ]
}

```

---

[![Devtroit](https://camo.githubusercontent.com/6afbabed3c3efbd24b8bd7dee8199898295ad70f7bd0607b31467db205f68385/687474703a2f2f64657674726f69742e636f6d2f696d672f6261646765732f62616467652d6d656469756d2e706e67)](https://camo.githubusercontent.com/6afbabed3c3efbd24b8bd7dee8199898295ad70f7bd0607b31467db205f68385/687474703a2f2f64657674726f69742e636f6d2f696d672f6261646765732f62616467652d6d656469756d2e706e67)

Proudly built in Detroit

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

4352d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5c96c41d0d99dc544740ceeb437dd1baa158fd0a8badc97936161821efbb07a0?d=identicon)[danielgsims](/maintainers/danielgsims)

### Embed Badge

![Health badge](/badges/danielgsims-php-siren/health.svg)

```
[![Health](https://phpackages.com/badges/danielgsims-php-siren/health.svg)](https://phpackages.com/packages/danielgsims-php-siren)
```

###  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)
