vendredi 22 décembre 2017

How to get the request payload from a PATCH request in express

I'm using Ember.js alongside an Express webserver. The default JSONApi adapter calls update records with a PATCH request to the server setting the Request Payload in the request to the server.

I'm having a hard time getting that data out of the request on my express server

Here is an example request Ember is sending to the server

enter image description here

The relevant code for the express server looks like this

app.route('/tags/:id')
  ...
  .patch(tag.updateTag);

// UpdateTag

function updateTag(req,res) {
  Tag.findById({_id: req.params.id}, (err,tag) => {
    if(err) res.send(err);
    Object.assign(tag, req.body).save((err,tag) => {
      if(err) res.send(err);

      res.json(TagSerializer.serialize(tag));
    });
  });
}




Aucun commentaire:

Enregistrer un commentaire