/** * @inheritdoc */ process(response) { let resource = response.request.resource; let processedBody = null; if (response.body instanceof Array) { processedBody = response.body.map(entity => halson(entity)); } else if (response.body) { processedBody = halson(response.body); let embeds = processedBody._embedded; if (embeds && embeds[resource.embedName]) { processedBody = processedBody.getEmbeds(resource.embedName); } } if (!processedBody) { return new Response(Object.assign({}, response, { body: null })); } let embedNames = resource.inlineEmbeds; if (embedNames) { let entities = processedBody instanceof Array ? processedBody : [processedBody]; for (let entity of entities) { this._processEntityEmbeds(entity, embedNames); } } return new Response(Object.assign({}, response, { body: processedBody })); }
Employee.get(req.params.id, function (err, employee) { if (!err) { if (employee) { let representation = halson(employee._doc).addLink('self', config.urlBase + '/v1/employees/' + employee._id) res.set('Content-Type', 'application/hal+json') res.status(200).json(representation) } } })
Employee.create(req.body, function (err, emp) { if (!err) { let representation = halson(emp._doc) representation.addLink('self', config.urlBase + '/v1/employees/' + emp._id) res.set('Content-Type', 'application/hal+json') res.status(201).json(representation) } else { res.status(404).json('error') } })
function makeHAL(data, links, embed) { var obj = halson(data) if (links && links.length > 0) { _.each(links, function (lnk) { obj.addLink(lnk.name, { href: lnk.href, title: lnk.title || '' }) }) } if (embed && embed.length > 0) { _.each(embed, function (item) { obj.addEmbed(item.name, item.data) }) } return obj }
dao.listAll(function(err, categoriaList){ if(err) { res.status(500).json(err); } else { if(categoriaList !== null && categoriaList.length >= 0){ //HAL json var resource = halson().addEmbed('categoriaList',categoriaList); res.json(resource) } else { res.status(404).json({message:'Something went wrong. Please Try again later.'}); } } });
processedBody = response.body.map(entity => halson(entity));
loadTodos: function(data) { _todos = halson(JSON.parse(data)); Store.emitChange(); },