Linking
In the Linked data section of the previous chapter, we defined that if an item in the catalog has an image assigned to it, this will be indicated with an HTTP header named Image-URL
.
Let's modify the findItemById
function in the V2 of the catalog. We will use the GridFS's existing function to check whether there is an image bound to the selected item; in case there is an image assigned to the item, its URL will be available to the response with the Image-Url header:
exports.findItemById = function (gfs, request, response) { CatalogItem.findOne({itemId: request.params.itemId}, function(error, result) { if (error) { console.error(error); response.writeHead(500, contentTypePlainText); return; } else { if (!result) { if (response != null) { response.writeHead(404, contentTypePlainText); response.end('Not Found'); } return; ...