flesh up the example

releases
Yanick Champoux 2023-11-01 15:28:47 -04:00
parent 5dd5e664e9
commit fb5cd7ce3a
1 changed files with 25 additions and 0 deletions

View File

@ -66,10 +66,15 @@ $registry->add_type(
self => sub($data,@) {
return "/articles/" . $data->{id};
},
},
relationships => {
'tags' => { type => 'tag' },
}
}
);
$registry->add_type('tag');
my $output = $registry->serialize('article', $data, { count => 2 } );
like $output => {
@ -83,6 +88,26 @@ like $output => {
"links"=> {
"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();