Quantcast
Channel: User Misha Krul - Stack Overflow
Viewing all articles
Browse latest Browse all 42

Answer by Misha Krul for Getting an undefined body in express PUT request

$
0
0

I figured it out.

I needed to pass express.json() as an argument when calling the user controller endpoint.

api/src/routes/user.ts:

router.put("/api/user/:userId", express.json(), userController.updateUser);

api/src/controllers/user.ts:

exports.updateUser = asyncHandler(async (req: any, res: any, next: any) => {      const { userId } = req.params;      const data = req.body;      const user = await updateUser(userId, data);      res.status(200).json({ user });    });

Data is being updated successfully now :)


Viewing all articles
Browse latest Browse all 42

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>