-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
55 lines (41 loc) · 1.23 KB
/
Copy pathexample.js
File metadata and controls
55 lines (41 loc) · 1.23 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
// index.js
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/greeting', function(req, res){
res.send("How are you!")
});
// app.get('/greeting/:name', function(req, res){
// var yourName = req.params.name;
// res.send("nice to meet you " + yourName);
// });
app.get('/salutations', function(req, res){
res.send("HELL YAH!")
});
app.get('/greeting/:color', function(req, res){
var yourColor = req.params.color;
res.send("Your color is " + yourColor)
})
app.post('/products', function(req, res){
//req.body is all the into coming in from the form-group
// we need to get name, color, price... out of req.body
var name = req.body.name ;
var color = req.body.color;
var price = req.body.price;
var product = {name: name, color: color, price:price};
res.json(product);
});
app.listen(3000, function(){
console.log("listening on port 3000");
});
app.post('/fish', function(req, res){
var type = req.body.type;
var length = req.body.length;
var color = req.body.color;
var fish = {type: type, length: length, color: color};
res.json(fish);
})
// req -> request
// res -> response