flesh up the example

This commit is contained in:
Yanick Champoux 2023-11-01 15:28:47 -04:00
parent 5dd5e664e9
commit fb5cd7ce3a

View File

@ -66,10 +66,15 @@ $registry->add_type(
self => sub($data,@) { self => sub($data,@) {
return "/articles/" . $data->{id}; return "/articles/" . $data->{id};
}, },
},
relationships => {
'tags' => { type => 'tag' },
} }
} }
); );
$registry->add_type('tag');
my $output = $registry->serialize('article', $data, { count => 2 } ); my $output = $registry->serialize('article', $data, { count => 2 } );
like $output => { like $output => {
@ -83,6 +88,26 @@ like $output => {
"links"=> { "links"=> {
"self"=> "/articles" "self"=> "/articles"
}, },
"data"=> [{
"type"=> "article",
"id"=> "1",
"attributes"=> {
"title"=> "JSON API paints my bikeshed!",
"body"=> "The shortest article. Ever.",
"created"=> "2015-05-22T14:56:29.000Z"
},
"relationships"=> {
"tags"=> {
"data"=> [{
"type"=> "tag",
"id"=> "1"
}, {
"type"=> "tag",
"id"=> "2"
}]
},
}
}],
}; };
done_testing(); done_testing();