2017 © Pedro Peláez
 

library hal-explorer

HalExplorer is a php client for exploring HAL Hateoas apis. HalExplorer is able to craft requests and follow links to resource relationships.

image

jmeyering/hal-explorer

HalExplorer is a php client for exploring HAL Hateoas apis. HalExplorer is able to craft requests and follow links to resource relationships.

  • Friday, December 9, 2016
  • by Jmeyering
  • Repository
  • 2 Watchers
  • 12 Stars
  • 4,413 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 11 Versions
  • 17 % Grown

The README.md

hal-explorer: Hateoas Api explorer.

Build Status Code Climate, (*1)

HalExplorer is a php client useful for exploring HAL formatted apis. HalExplorer is able to craft requests and follow links to retreive, create, update and delete resource relationships., (*2)

The codebase is fully covered by phpspec and extensively documented., (*3)

Install

composer require jmeyering/hal-explorer, (*4)

Docs

readthedocs, (*5)

Api Documentation

To generate api documentation use whatever phpdoc generation tool you want but apigen is included with the composer deps. Just run vendor/bin/apigen generate to create the documentation, then point your browser to public/index.html to view., (*6)

PSR7

The library makes exclusive use of [PSR7 messages]0. Whatever http client is used internally must return PSR7 Message interfaces., (*7)

Usage

To use the exploration feature of the library we need to think about our responses and their included _links as objects and relationships., (*8)

Fetching, Creating, Updating, and Deleting are the primary actions to perform on a related object. HalExplorer exposes this functionality with the getRelation, createRelation, updateRelation, patchUpdateRelation and deleteRelation methods., (*9)

As expected, these methods map to the GET, POST, PUT, PATCH and DELETE HTTP verbs., (*10)

$explorer->createRelation($object, "association");

Example

We will use the haltalk api as an endpoint example and guzzlehttp/guzzle for our HTTP Client., (*11)

// This Example creates a new account with haltalk and creates a post from that
// account.
$client = new \GuzzleHttp\Client();
$explorer = new \HalExplorer\Explorer();
$adapter = new \HalExplorer\ClientAdapters\Adapter();

$adapter->setClient($client);
$explorer->setAdapter($adapter)->setBaseUrl("http://haltalk.herokuapp.com");

// The haltalk api requires both "application/hal+json" and, application/json"
// Accept headers to work. hal-explorer only adds "application/hal+json" by
// default so we need to override this default value.
$explorer->setDefaults(function($original){
    $original["headers"]["Accept"] = "application/hal+json, application/json";

    return $original;
});

$username = "myuniqueusername";

// Enter the haltalk api and return a PSR7 ResponseInterface
$entrypoint = $explorer->enter();

// Create an account with haltalk.
$accountResponse = $explorer->createRelation($entrypoint, "signup", [
    "body" => '{
        "username": "'.$username.'",
        "password": "password"
    }'
]);

// Retreive my account information using thy "me" link on the entrypoint.
// Because this is a templated link, we must pass templated data along.
$myAccount = $explorer->getRelation($entrypoint, "me", [
    "template" => [
        "name" => $username,
    ],
]);

// Create a post from my account. This resource requires basic auth.
$post = $explorer->createRelation($myAccount, "posts", [
    "body" => '{
        "content": "This is my post Content"
    }',
    "auth" => [
        $username,
        "password"
    ]
]);

// Haltalk return the post location in a response header. We can fetch that
// information using the PSR7 method, getHeaderLine()
$postLocation = $post->getHeaderLine("location");

The Versions

09/12 2016

dev-master

9999999-dev

HalExplorer is a php client for exploring HAL Hateoas apis. HalExplorer is able to craft requests and follow links to resource relationships.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jared Meyering

21/10 2016

1.5.0

1.5.0.0

HalExplorer is a php client for exploring HAL Hateoas apis. HalExplorer is able to craft requests and follow links to resource relationships.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jared Meyering

08/09 2016

1.4.0

1.4.0.0

HalExplorer is a php client for exploring HAL Hateoas apis. HalExplorer is able to craft requests and follow links to resource relationships.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jared Meyering

31/08 2016

1.3.2

1.3.2.0

HalExplorer is a php client for exploring HAL Hateoas apis. HalExplorer is able to craft requests and follow links to resource relationships.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jared Meyering

30/08 2016

1.3.1

1.3.1.0

HalExplorer is a php client for exploring HAL Hateoas apis. HalExplorer is able to craft requests and follow links to resource relationships.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jared Meyering

30/08 2016

1.3.0

1.3.0.0

HalExplorer is a php client for exploring HAL Hateoas apis. HalExplorer is able to craft requests and follow links to resource relationships.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jared Meyering

22/08 2016

1.2.2

1.2.2.0

HalExplorer is a php client for exploring HAL Hateoas apis. HalExplorer is able to craft requests and follow links to resource relationships.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jared Meyering

18/07 2016

1.2.1

1.2.1.0

HalExplorer is a php client for exploring HAL Hateoas apis. HalExplorer is able to craft requests and follow links to resource relationships.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jared Meyering

04/12 2015

1.2.0

1.2.0.0

HalExplorer is a php client for exploring HAL Hateoas apis. HalExplorer is able to craft requests and follow links to resource relationships.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jared Meyering

04/08 2015

1.1.0

1.1.0.0

HalExplorer is a php client for exploring HAL Hateoas apis. HalExplorer is able to craft requests and follow links to resource relationships.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jared Meyering

04/08 2015

1.0.0

1.0.0.0

HalExplorer is a php client for exploring the HAL Hateoas apis. HalExplorer is able to craft requests and follow links to resource relationships.

  Sources   Download

The Requires

 

The Development Requires

by Jared Meyering