PHP code example of php-pico / http-link
1. Go to this page and download the library: Download php-pico/http-link 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/ */
php-pico / http-link example snippets
use PhpPico\Http\Link\Link;
$link = new Link(
href: '/api/users/{id}',
rels: ['next'],
attributes: ['type' => 'application/json'],
);
$link->getHref(); // '/api/users/{id}'
$link->isTemplated(); // true (href contains '{')
$link->getRels(); // ['next']
$link->getAttributes(); // ['type' => 'application/json']
// Evolvable methods return new instances
$link = $link->withRel('prev');
$link = $link->withoutRel('next');
$link = $link->withAttribute('hreflang', 'en');
$link = $link->withoutAttribute('type');
$link = $link->withHref('/api/users/42');
use PhpPico\Http\Link\Link;
use PhpPico\Http\Link\LinkProvider;
$provider = new LinkProvider([
new Link('/api/users', ['self']),
new Link('/api/users/{id}', ['item']),
]);
$provider->getLinks(); // iterable<LinkInterface>
$provider->getLinksByRel('item'); // iterable<LinkInterface> matching the rel
// Evolvable methods return new instances
$provider = $provider->withLink(new Link('/api/users?page=2', ['next']));
$provider = $provider->withoutLink($link);