router.route("/:id").put((req, res) => { const movieId = req.params.id; const movie = req.body; console.log("Editing movie: ", movieId, " to be ", movie); res.json({message: "You are trying to edit a movie: ", movieId}); // res.json(data); });
router.route('/movies/:id') .put(function(req,res){ }) .get(function(req,res){ }) .delete(function(req,res){ });
routes() { this.app .route('/') .get((req, res) => res.status(200).json({ message: 'Hello world!' })); this.app.route('/api/crushs').get(CrushRoutes.getAll); this.app.route('/api/crushs/:id').get(CrushRoutes.getByID); this.app.route('/api/crushs').post(CrushRoutes.create); this.app.route('/api/crushs/:id').put(CrushRoutes.update); this.app.route('/api/crushs/:id').delete(CrushRoutes.delete); }
promoRouter.route('/:promoId') .all(function(req, res, next){ res.writeHead(200, {'Content-Type':'text-plain'}); next(); }) .get(function(req, res, next){ res.end('I will return everything of the object'); }) .put(function(req, res, next){ res.end(' i will update object '+ req.params.promoId+ ' with '+ req.body.name); }) .delete(function(req, res, next){ res.end('i will only delete '+ req.params.promoId); });
router.route('/note/update/:id') .put(function(req, res){ Notes.update({_id: req.params.id}, {$set: {title : req.body.title, description : req.body.description}}).exec((err, note) => { if (err) { console.log(err) return res.status(501).json({ message: err }) } else { return res.status(200).json({msg: 'note updated'}) } }) })
// SPECIFIC DISH dishRouter.route('/:dishId') .all(function(req, res, next){ res.writeHead(200, {'Content-Type': 'text-plain'}); next(); }) .get(function(req, res, next){ res.end('You want info for the dish '+ req.params.dishId); }) .put(function(req, res, next){ res.end('you want to update '+ req.params.dishId + ' with ' + req.body.name + ' '+ req.body.name); });
UserRouteId.put(function(req, res) { User.findById(req.params.user_id, function(err, user) { if (err) res.send(err); user.name = req.body.name; user.save(function(err) { if (err) res.send(err); res.json({ message: 'Usuario Atualizado!' }); }); }); });
routes(){ this.app.route('/').get( (req,res) => res.status(200).json({"result": "Hello World"}) ); this.app.route('/api/crushs').get( (req,res)=> this.controller.select(req, res)) this.app.route('/api/crushs/:id').get( (req,res)=> this.controller.selectOne(req, res)) this.app.route('/api/crushs/:id').delete( (req,res)=> this.controller.delete(req, res)) this.app.route('/api/crushs/:id').put( (req,res)=> this.controller.update(req, res)) this.app.route('/api/crushs').post( (req,res)=> this.controller.insert(req, res)) }
// API specific to a student. router.route('/students/:student_id') .get(function(req,res){ res.json({message:'get the student with id = '+req.params.student_id}); }) .put(function(req,res){ res.json({message:'find and update student with id ='+req.params.student_id}) }) .delete(function(req,res){ res.json({message:'find and delete student with id ='+req.params.student_id}) });
//----------------------------------------------------------------------------------------------- //You can create chainable route handlers for a route path by using app.route(). Because the path is specified at a single location, creating modular routes is helpful, as is reducing redundancy and typos router.route('/route-test') .get(function (req, res) { res.send('Get a random book') }) .post(function (req, res) { res.send('Add a book') }) .put(function (req, res) { res.send('Update the book') })
// or app.route('/products') .get(function (req, res, next) {}) .post(function (req, res, next) {}) .put(function (req, res, next) {})
// SPECIFIC DISH dishRouter.route('/:dishId') .all(function(req, res, next){ res.writeHead(200, {'Content-Type': 'text-plain'}); next(); }) .get(function(req, res, next){ res.end('You want info for the dish '+ req.params.dishId); }) .put(function(req, res, next){ res.end('you want to update '+ req.params.dishId + ' with ' + req.body.name + ' '+ req.body.name); });
helpRouter.route('/help') .get((request, response) => { response.send('<h3>/api/v2/help got GET - text/html directly returned from server.js</h3>'); }) .post((request, response) => { response.send('<h3>/api/v2/help got POST - text/html directly returned from server.js</h3>'); }) .put((request, response) => { response.send('<h3>/api/v2/help got PUT - text/html directly returned from server.js</h3>'); });
router.route('/movies/:id') .put(function(req,res){ }) .get(function(req,res){ }) .delete(function(req,res){ });
// SPECIFIC DISH dishRouter.route('/:dishId') .all(function(req, res, next){ res.writeHead(200, {'Content-Type': 'text-plain'}); next(); }) .get(function(req, res, next){ res.end('You want info for the dish '+ req.params.dishId); }) .put(function(req, res, next){ res.end('you want to update '+ req.params.dishId + ' with ' + req.body.name + ' '+ req.body.name); });