Express/node.js 204 HTTP code response issue -


here code:

.put(function(req, res) {   user.findbyid(req.params.user_id, function(err, user) {     if(err) return res.send(err);      user.dateedited = new date();     user.save(function(err) {       if(err) return res.send(err);        return res.status(204).json(customhttpcodereponses.updated(user))     });   }); });       

part of middleware called customhttpcodereponses

updated: function(data) {   return {     code: 204,     status: 'success',     message: 'resource updated (or soft deleted)',     data: data   }; } 

i figured out, 204 not supposed return data, not getting back. have data see changed. how hande response code then?

have in mind if use

res.status(200).json(customhttpcodereponses.updated(user)) 

data shown.

if need explanation, please ask.

yes, correct. http status not allowed messages because means "no content". if send content, use other statuses. details @ document: http://www.w3.org/protocols/rfc2616/rfc2616-sec10.html. there part: "the 204 response must not include message-body, , terminated first empty line after header fields."

if want send not content metadata addictional info, in document there part : "the response may include new or updated metainformation in form of entity-headers, if present should associated requested variant.". think formal answer question.

if not formal, use status '200' metadata content.

edit: send data in header :

res.header(field, [value]) 

Comments