-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent-6.js
More file actions
57 lines (50 loc) · 1.76 KB
/
Copy pathStudent-6.js
File metadata and controls
57 lines (50 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var express=require('express'); //import express for express router
var morgan=require('morgan'); //for used to logging
var bodyParser=require('body-parser');
var hostname='localhost';
var port=3000; //custom hostname and port address
var app=express();
app.use(morgan('dev'));
var movieRouter=express.Router();
movieRouter.use(bodyParser.json());
movieRouter.route('/')
.all(function(req,res,next){
res.writeHead(200,{'Content-Type':'text/plain'});
next();
}) // http methods GET,POST,PUT,DELETE etc
.get(function(req,res,next){
res.end('We Will Send The Movie Details');
})
.post(function(req,res,next){
res.end('We Will add The Movie Details'+req.body.name+'and'+req.body.description);
})
.put(function(req,res,next){
res.end('We Will Update The Movie details'+req.body.name+'and'+req.body.description);
})
.delete(function(req,res,next){
res.end('Deleting the Movies');
});
// particular movie
movieRouter.route('/:movieId')
.all(function(req,res,next){
res.writeHead(200,{'Content-Type':'text/plain'});
next();
})
.get(function(req,res,next){
res.end('we will send the details of : '+ req.params.movieId);
})
.put(function(req,res,next){
res.write('Updating the Movie detail:'+req.params.movieId);
res.end('we will update the Movie details:'+req.body.name+'and'+req.body.description);
})
.post(function(req,res,next){
res.write('inserting the Movie details:'+req.params.movieId);
res.end('we will add the Movie detail:'+req.body.name+' and Description '+req.body.description);
})
.delete(function(req,res,next){
res.end('Deleting the Movie'+req.params.movieId);
});
app.use('/movies',movieRouter);
app.listen(port,hostname,function(){
console.log(`server Running at htpp://${hostname}:${port}`);
})