Content Negotiation

Documentation in progress.

Tips

By default, your REST entities will return HAL-flavored JSON. If, for whatever reason, you want to return vanilla JSON, one trick is to have your entities implement JsonSerializable. This standard PHP interface defines a single method, jsonSerialize(), which allows you to return an associative array representation to serialize as JSON. As an example:

class MyEntity implements \JsonSerializable
{
    /* ... */

    public function jsonSerialize()
    {
        return [
            'name' => $this->getName(),
        ];
    }
}

would yield:

{
  "name": "the name returned from getName()
}

when cast to JSON.

Images in the documentation, and the API Tools Admin UI itself, still refer to Apigility. This is due to the fact that we only recently transitioned the project to its new home in the Laminas API Tools. Rest assured that the functionality remains the same.