diff --git a/examples/index.html b/examples/index.html index d4f5a73..7ee8985 100644 --- a/examples/index.html +++ b/examples/index.html @@ -33,6 +33,11 @@

Errors

  • All options
  • +

    Misc

    + + diff --git a/examples/meta_only.php b/examples/meta_only.php new file mode 100644 index 0000000..66544fb --- /dev/null +++ b/examples/meta_only.php @@ -0,0 +1,24 @@ +add_meta('foo', 'bar'); + +/** + * sending the response + */ + +$jsonapi->send_response(); diff --git a/src/response.php b/src/response.php index f7871a7..6e07b8f 100644 --- a/src/response.php +++ b/src/response.php @@ -88,6 +88,31 @@ public function __toString() { return $this->get_json(); } +/** + * generates an array for the whole response body + * + * @see jsonapi.org/format + * + * @return array, containing: + * - links + * - meta + */ +public function get_array() { + $response = array(); + + // links + if ($this->links) { + $response['links'] = $this->links; + } + + // meta data + if ($this->meta_data) { + $response['meta'] = $this->meta_data; + } + + return $response; +} + /** * returns the whole response body as json * it generates the response via ->get_array()