0
0
Expressframework~10 mins

HATEOAS concept overview in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to send a JSON response with a self link in Express.

Express
res.json({ message: 'Hello', links: [{ rel: 'self', href: [1] }] });
Drag options to blanks, or click blank then click option'
A'/home'
B'http://example.com/api/resource'
C'/api/resource'
D'/api/other'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a full URL instead of a relative path
Using a different resource path
2fill in blank
medium

Complete the code to add a link to update the resource in the HATEOAS response.

Express
res.json({ message: 'Resource', links: [{ rel: 'update', method: 'PUT', href: [1] }] });
Drag options to blanks, or click blank then click option'
A'/api/resource/update'
B'/api/resource'
C'/api/resource/edit'
D'/api/resource/modify'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding extra path segments for update
Using GET method instead of PUT
3fill in blank
hard

Fix the error in the code to correctly add a 'delete' link in the HATEOAS response.

Express
res.json({ message: 'Delete me', links: [{ rel: 'delete', method: [1], href: '/api/item/1' }] });
Drag options to blanks, or click blank then click option'
A'GET'
B'PUT'
C'POST'
D'DELETE'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'GET' method for delete link
Confusing 'POST' with 'DELETE'
4fill in blank
hard

Fill both blanks to create a HATEOAS response with links for 'self' and 'list' actions.

Express
res.json({ data: resource, links: [{ rel: [1], href: '/api/resource/1' }, { rel: [2], href: '/api/resource' }] });
Drag options to blanks, or click blank then click option'
A'self'
B'list'
C'update'
D'delete'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping 'self' and 'list' rel values
Using unrelated rel values
5fill in blank
hard

Fill all three blanks to build a HATEOAS response with 'self', 'update', and 'delete' links.

Express
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' } ] });
Drag options to blanks, or click blank then click option'
A'self'
B'PUT'
C'update'
D'POST'
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST instead of PUT for update
Mixing rel values and methods