Complete the code to send a JSON response with a self link in Express.
res.json({ message: 'Hello', links: [{ rel: 'self', href: [1] }] });The href should be the relative URL of the current resource, which is '/api/resource' here.
Complete the code to add a link to update the resource in the HATEOAS response.
res.json({ message: 'Resource', links: [{ rel: 'update', method: 'PUT', href: [1] }] });The update link usually points to the resource URL itself with the HTTP method indicating the action, here 'PUT' on '/api/resource'.
Fix the error in the code to correctly add a 'delete' link in the HATEOAS response.
res.json({ message: 'Delete me', links: [{ rel: 'delete', method: [1], href: '/api/item/1' }] });The HTTP method for deleting a resource is 'DELETE'. Using 'GET' or others will not perform deletion.
Fill both blanks to create a HATEOAS response with links for 'self' and 'list' actions.
res.json({ data: resource, links: [{ rel: [1], href: '/api/resource/1' }, { rel: [2], href: '/api/resource' }] });The 'self' link points to the current resource, and the 'list' link points to the collection of resources.
Fill all three blanks to build a HATEOAS response with 'self', 'update', and 'delete' links.
res.json({ item: obj, links: [ { rel: [1], method: 'GET', href: '/api/item/42' }, { rel: [2], method: [3], href: '/api/item/42' }, { rel: 'delete', method: 'DELETE', href: '/api/item/42' } ] });The 'self' link uses GET method. The 'update' link uses PUT method. The 'delete' link is already correct.