PHP code example of vlucas / hyperspan
1. Go to this page and download the library: Download vlucas/hyperspan library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vlucas / hyperspan example snippets
$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();
$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();