Thursday, 21 May 2020

[Express] How to do PATCH request on a specific object

GoalTo do a patch request on an object with the given IDHere's my database for reference: https://music-json-server.now.sh/db.json/​What I'm trying to do:Front-endexport const editStream = (id, formValues) => async (dispatch) => { const response = await streams.patch(`edit/${id}`, formValues); //where ID is a variable and can be any number! }; Express:How do I pass the "id" to app.patch() route?How do I tell app.patch() to find the object in "streams" array with the matching id?​Here's what I have so farapp.patch("/edit", cors(corsOptions), async (req, res, next) => { const data = req.body; try { const response = await axios.patch( "https://music-json-server.now.sh/db.json", data ); } catch (err) { next(err); } });

Submitted May 22, 2020 at 06:36AM by badboyzpwns

No comments:

Post a Comment