Code Monkey home page Code Monkey logo

hal-explorer's People

Contributors

jmeyering avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hal-explorer's Issues

Overriding "Content-Type" header for multipart-posts not possible

Hi, it's me again ;-)

I just tried to do a multipart post on our client's HAL-API and had a really hard time setting the "Content-Type"-Header. It's set by default to "application/json" but for something like this to work:

        $this->explorer->createRelation($this->enter(), 'documents', [
            'multipart' => [
                [
                    'name'     => 'content',
                    'filename' => 'filename',
                    'contents' => $data,
                ]
            ]
        ]

...the "Content-Type" must be empty, so that Guzzle sets is on its own.

I accomplished that by calling:

       $this->explorer->setDefaults(function ($original) {
            $original["headers"]["Authorization"] = 'bearer '.$this->getAuthorizationToken();
            unset($original["headers"]["Content-Type"]);

            return $original;
        });

As there's no "getConfiguredDefaultCallback" I couldn't write a workaround like:

  1. Get current callback
  2. Define a new one that removes the "Content-Type" header
  3. Reset to the old callback

So it is possible but very cumbersome and hard to reset afterwards.

Any ideas?

AbstractAdapter::setClient() isn't fluent

Like with Exploder's methods, it would be nice if AbstractAdapter::setClient() could return $this to make the interface fluent.

This would allow for a fluent initialization like this:

$this->explorer = (new Explorer())
    ->setAdapter((new Adapter())->setClient(new Client()))
    ->setBaseUrl('http://haltalk.herokuapp.com')
    ->setDefaults(function ($original) {
        $original["headers"]["Authorization"] = 'bearer '.$this->getAuthorizationToken();

        return $original;
    })
;

HyperMediaParser()->getLink() can return an array of objects, not just a single object

First, thank you so much for putting this together.

In \HalExplorer\Explorer::followLink() the HyperMediaParser()->getLink() method can return an array of objects. So the property_exists() check on line 242 can throw a few warnings such as Warning: First parameter must either be an object or the name of an existing class in ....

For my needs, I needed to grab $link[0] before the property_exists() call.

Now, I don't know if this is an issue with the API I'm using (It's a new, internal API at my university), or whether this is something that your library should account for. I'm new to HAL APIs.

If this is something that the HAL-explorer library should deal with, I'm happy to create a PR here, but would love some advice on how you think this should be handled.

Adapter::patch() is missing but declared in AdapterInterface

Sorry to bother you again but, as stated in the issue's description, the Adapter currently creates PHP errors because it doesn't implement the patch() method.

When I'm getting more confident with Git(Hub) I will create pull requests but for now I think what is missing is only:

    /**
     * Perform a patch request
     *
     * @param string $uri
     * @param array  $options All options for the request, will be passed to the
     * client
     *
     * @return ResponseInterface
     */
    public function patch($uri, array $options = [])
    {
        return $this->getClient()->patch($uri, $options);
    }

Explorer::makeRequest(): Wrong URL generation for APIs with absolute URLs

I'm working with an API that exposes absolute URLs instead of relative ones, like:

"doc:documents" : { "href" : "https://customer.com/rest/api/documents" }

The base URL is https://customer.com/rest/api.

When I now call $explorer->getRelation($response, 'documents') it creates the URI https://customer.com/rest/api//rest/api/documents because of the way Exploder::makeRequest() assumes that the path given is relative.

I would suggest something like:

        // Remove the base url from the uri if it's an absolute one
        $parsed = parse_url(str_replace($this->getBaseUrl(), '', $uri));

        $path = $parsed["path"];

        // Trim leading slash if it exists
        $path = ltrim($path, "/");

Doing the ltrim later makes sure that only slashes from the extracted path are removed. Also this way network paths like //github.com/rest/api won't be broken.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.