PHPackages                             vlucas/hyperspan - 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. vlucas/hyperspan

ActiveLibrary[API Development](/categories/api)

vlucas/hyperspan
================

Build a Hypermedia API response once and return it in multiple formats

0.2.2(11y ago)1813.4k↑75%2BSDPHPPHP &gt;=5.3.2

Since Aug 5Pushed 2y ago1 watchersCompare

[ Source](https://github.com/vlucas/hyperspan-php)[ Packagist](https://packagist.org/packages/vlucas/hyperspan)[ Docs](http://github.com/vlucas/hyperspan)[ RSS](/packages/vlucas-hyperspan/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (10)Used By (0)

Hyperspan
=========

[](#hyperspan)

Build a Hypermedia API response once in code and return it in multiple formats

**NOTE:** Currently in heavy active development, and some things may change, so be sure to version lock for stability.

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

[](#installation)

Use the Composer [basic usage guide](http://getcomposer.org/doc/01-basic-usage.md), or use the following commands:

```
curl -s http://getcomposer.org/installer | php
php composer.phar require vlucas/hyperspan 0.x
php composer.phar install

```

Overview
--------

[](#overview)

There are two main components of Hyperspan: `Hyperspan\Response`, which is used to build an API response with specific attributes and types of data, and `Hyperspan\Formatter`, which is used to output the data in a sepcific Hypermedia API response format.

Supported Hypermedia Formats
----------------------------

[](#supported-hypermedia-formats)

- [HAL](http://stateless.co/hal_specification.html) (+forms)
- [Siren](https://github.com/kevinswiber/siren)

HAL JSON Usage
--------------

[](#hal-json-usage)

The following code:

```
$res = new Hyperspan\Response();
$res->setProperties(array(
        'foo' => 'bar',
        'bar' => 'baz'
    ))
    ->addLink('self', 'http://localhost/foo/bar');
    ->addForm('add-item', array(
        'method' => 'POST',
        'href' => '/items',
        'fields' => array(
            'name' => array('type' => 'string'),
            'body' => array('type' => 'text')
        )
    ))
    ->addItem('item', array(
        'some' => true,
        'something' => 'else',
        'three' => 3
    ));

$format = new Hyperspan\Formatter\Hal($res);

header('Content-Type', 'application/hal+json');
echo $format->toJson();
```

Will output the following JSON structure in [HAL](http://stateless.co/hal_specification.html).

```
{
  "foo": "bar",
  "bar": "baz",
  "_embedded": {
    "item": {
      "some": true,
      "something": "else",
      "three": 3
    }
  ],
  "_forms": [
    "add-item": {
      "method": "POST",
      "href": "/items",
      "fields": [
        "name": { "type": "string" },
        "body": { "type": "text" }
      ]
    }
  ],
  "_links": [
    "self": { "href": "http://localhost/foo/bar" }
  ]
}

```

Siren JSON Usage
----------------

[](#siren-json-usage)

The following code:

```
$res = new Hyperspan\Response();
$res->title = 'Siren Sample JSON Response with Hyperspan';
$res->setProperties(array(
        'foo' => 'bar',
        'bar' => 'baz'
    ))
    ->addLink('self', 'http://localhost/foo/bar');
    ->addForm('add-item', array(
        'title' => 'Add Item',
        'method' => 'POST',
        'href' => '/items',
        'fields' => array(
            array('name' => 'name', 'type' => 'string'),
            array('name' => 'body', 'type' => 'text')
        )
    ))
    ->addItem('item', array(
        'some' => true,
        'something' => 'else',
        'three' => 3
    ));

$format = new Hyperspan\Formatter\Siren($res);

header('Content-Type', 'application/vnd.siren+json');
echo $format->toJson();
```

Will output the following JSON structure in [Siren](https://github.com/kevinswiber/siren).

```
{
  "title": "Siren Sample JSON Response with Hyperspan",
  "properties": {
    "foo": "bar",
    "bar": "baz"
  },
  "entities": [
    {
      "properties": {
        "some": true,
        "something": "else",
        "three": 3
      }
    }
  ],
  "actions": [
    {
      "name": "add-item",
      "title": "Add Item",
      "method": "POST",
      "href": "/items",
      "fields": [
        { "name": "name", "type": "string" },
        { "name": "body", "type": "text" }
      ]
    }
  ],
  "links": [
    { "rel": [ "self" ], "href": "http://localhost/foo/bar" }
  ]
}

```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

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 ~43 days

Recently: every ~34 days

Total

8

Last Release

4366d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/187?v=4)[Vance Lucas](/maintainers/vlucas)[@vlucas](https://github.com/vlucas)

---

Top Contributors

[![vlucas](https://avatars.githubusercontent.com/u/187?v=4)](https://github.com/vlucas "vlucas (29 commits)")

---

Tags

apihalhypermediaSirenhypermedia apisiren jsonhal json

### Embed Badge

![Health badge](/badges/vlucas-hyperspan/health.svg)

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

###  Alternatives

[zircote/hal

A PHP implementation of HAL http://stateless.co/hal\_specification.html

94228.2k2](/packages/zircote-hal)[m165437/laravel-blueprint-docs

API Blueprint Renderer for Laravel

22779.0k](/packages/m165437-laravel-blueprint-docs)[nilportugues/hal

HAL+JSON &amp; HAL+XML API transformer outputting valid API responses.

317.7k2](/packages/nilportugues-hal)[simondevelop/sirene

Librairie facilitant l'utilisation de l'API sirene de l'insée

1026.4k1](/packages/simondevelop-sirene)[nilportugues/laravel5-haljson

Laravel 5 HAL+JSON API Transformer Package

151.0k](/packages/nilportugues-laravel5-haljson)

PHPackages © 2026

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