@@ -56,8 +56,10 @@ will output
5656 "data" : {
5757 "type" : " people" ,
5858 "id" : " 123" ,
59- "first_name" : " John" ,
60- "last_name" : " Dow" ,
59+ "attributes" : {
60+ "first_name" : " John" ,
61+ "last_name" : " Dow"
62+ },
6163 "links" : {
6264 "self" : " http:\/\/ example.com\/ people\/ 123"
6365 }
@@ -110,7 +112,9 @@ will output
110112 "data" : {
111113 "type" : " sites" ,
112114 "id" : " 1" ,
113- "name" : " JSON API Samples" ,
115+ "attributes" : {
116+ "name" : " JSON API Samples"
117+ },
114118 "links" : {
115119 "self" : " http:\/\/ example.com\/ sites\/ 1" ,
116120 "posts" : {
@@ -125,13 +129,17 @@ will output
125129 {
126130 "type" : " people" ,
127131 "id" : " 123" ,
128- "first_name" : " John" ,
129- "last_name" : " Dow"
132+ "attributes" : {
133+ "first_name" : " John" ,
134+ "last_name" : " Dow"
135+ }
130136 },
131137 {
132138 "type" : " comments" ,
133139 "id" : " 456" ,
134- "body" : " Included objects work as easy as basic ones" ,
140+ "attributes" : {
141+ "body" : " Included objects work as easy as basic ones"
142+ },
135143 "links" : {
136144 "self" : " http:\/\/ example.com\/ comments\/ 456" ,
137145 "author" : {
@@ -145,7 +153,9 @@ will output
145153 {
146154 "type" : " comments" ,
147155 "id" : " 789" ,
148- "body" : " Let's try!" ,
156+ "attributes" : {
157+ "body" : " Let's try!"
158+ },
149159 "links" : {
150160 "self" : " http:\/\/ example.com\/ comments\/ 789" ,
151161 "author" : {
@@ -159,8 +169,10 @@ will output
159169 {
160170 "type" : " posts" ,
161171 "id" : " 321" ,
162- "title" : " Included objects" ,
163- "body" : " Yes, it is supported" ,
172+ "attributes" : {
173+ "title" : " Included objects" ,
174+ "body" : " Yes, it is supported"
175+ },
164176 "links" : {
165177 "author" : {
166178 "linkage" : {
@@ -216,22 +228,20 @@ Note that output does not contain objects from neither ```posts``` nor ```posts.
216228 "data" : {
217229 "type" : " sites" ,
218230 "id" : " 1" ,
219- "name" : " JSON API Samples" ,
231+ "attributes" : {
232+ "name" : " JSON API Samples"
233+ },
220234 "links" : {
221- "self" : " http:\/\/ example.com\/ sites\/ 1" ,
222- "posts" : {
223- "linkage" : {
224- "type" : " posts" ,
225- "id" : " 321"
226- }
227- }
235+ "self" : " http:\/\/ example.com\/ sites\/ 1"
228236 }
229237 },
230238 "included" : [
231239 {
232240 "type" : " people" ,
233241 "id" : " 123" ,
234- "first_name" : " John"
242+ "attributes" : {
243+ "first_name" : " John"
244+ }
235245 }
236246 ]
237247}
@@ -342,6 +352,68 @@ class YourSchema extends SchemaProvider
342352}
343353```
344354
355+ ### Show top level links and meta information
356+
357+ ``` php
358+ $author = Author::instance('123', 'John', 'Dow');
359+ $meta = [
360+ "copyright" => "Copyright 2015 Example Corp.",
361+ "authors" => [
362+ "Yehuda Katz",
363+ "Steve Klabnik",
364+ "Dan Gebhardt"
365+ ]
366+ ];
367+ $links = new DocumentLinks(
368+ null,
369+ 'http://example.com/people?first',
370+ 'http://example.com/people?last',
371+ 'http://example.com/people?prev',
372+ 'http://example.com/people?next'
373+ );
374+
375+ $encoder = Encoder::instance([
376+ Author::class => AuthorSchema::class,
377+ Comment::class => CommentSchema::class,
378+ Post::class => PostSchema::class,
379+ Site::class => SiteSchema::class
380+ ], new JsonEncodeOptions(JSON_PRETTY_PRINT));
381+
382+ echo $encoder->encode($author, $links, $meta) . PHP_EOL;
383+ ```
384+
385+ will output
386+
387+ ``` json
388+ {
389+ "meta" : {
390+ "copyright" : " Copyright 2015 Example Corp." ,
391+ "authors" : [
392+ " Yehuda Katz" ,
393+ " Steve Klabnik" ,
394+ " Dan Gebhardt"
395+ ]
396+ },
397+ "links" : {
398+ "first" : " http:\/\/ example.com\/ people?first" ,
399+ "last" : " http:\/\/ example.com\/ people?last" ,
400+ "prev" : " http:\/\/ example.com\/ people?prev" ,
401+ "next" : " http:\/\/ example.com\/ people?next"
402+ },
403+ "data" : {
404+ "type" : " people" ,
405+ "id" : " 123" ,
406+ "attributes" : {
407+ "first_name" : " John" ,
408+ "last_name" : " Dow"
409+ },
410+ "links" : {
411+ "self" : " http:\/\/ example.com\/ people\/ 123"
412+ }
413+ }
414+ }
415+ ```
416+
345417## Questions?
346418
347419Do not hesitate to contact us on [ ![ Gitter] ( https://badges.gitter.im/Join%20Chat.svg )] ( https://gitter.im/neomerx/json-api ) or post an [ issue] ( https://github.com/neomerx/json-api/issues ) .
0 commit comments