forked from WBWeb/FullStackWebDevelopment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
55 lines (43 loc) · 1.05 KB
/
server.js
File metadata and controls
55 lines (43 loc) · 1.05 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
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
var ingredients = [
{
"id" : "234fjj",
"text" : "Eggs"
},
{
"id" : "327fjg",
"text" : "Milk"
},
{
"id" : "996yhu",
"text" : "Cheese"
},
{
"id" : "449klo",
"text" : "Pancakes"
}
];
app.get('/', function(request, response){
response.send(ingredients);
}
);
app.get('/funions', function(request,response){
response.send('yo give me some funions!');
});
app.post('/', function(request, response){
var ingredient = request.body;
if (!ingredient || ingredient === "") {
response.status(500).send({error: "Your ingredient must not be empty"});
} else {
ingredients.push(ingredient);
response.status(200).send (ingredients);
}
});
app.put('')
app.listen(3000, function() {
console.log('This API is running on port 3000');
});