Skip to content

Instantly share code, notes, and snippets.

@alganet
Created May 27, 2012 01:36
Show Gist options
  • Save alganet/2795839 to your computer and use it in GitHub Desktop.
Save alganet/2795839 to your computer and use it in GitHub Desktop.
A HATEOAS, RESTful HTTP client for PHP.
<?php
use Respect\Http\Hypermedia as hy;
//All synopses from movies featuring Will Smith as an actor.
hy::with("netflix", "http://api.netflix.com/")
->with("schema", "http://schemas.netflix.com/")
->get("netflix/catalog/people", array('term' => 'Will Smith'))
->rel("schema/catalog/person/filmography")
->rel("schema/catalog/titles/synopsis")->send();
/*
Sample above line by line:
1 - Registers a netflix namespace to shorten further method calls
2 - Register a schema namespace
3 - GETs a page from the Netflix API
4 - Searches links related as filmographies.
5 - On links related, searches for synopses.
See the Netflix API Reference for more information on REST and Hypermedia relations.
Several requests on each Netflix APIs are done. Caching can help heavy clients if necessary, constant open sockets could also help using stream_select();
*/
@twogood
Copy link

twogood commented Sep 14, 2012

Alexandre, is the Respect\Http\Hypermedia implementation available somewhere? It looks very interesting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment