Skip to content

Commit ee2b83b

Browse files
committed
few fixes in r3.2
1 parent 3949b7e commit ee2b83b

File tree

1 file changed

+4
-5
lines changed
  • module3-crud-and-data-models/r3.2-models-and-controllers-in-mongoose

1 file changed

+4
-5
lines changed

module3-crud-and-data-models/r3.2-models-and-controllers-in-mongoose/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const app = express();
4848

4949
app.get("/foods", async (request, response) => {
5050
const foods = await foodModel.find({});
51-
response.send(foods);
51+
response.json(foods);
5252
});
5353

5454
module.exports = app;
@@ -66,7 +66,7 @@ Example:
6666
app.post("/food", async (request, response) => {
6767
const food = new foodModel(request.body);
6868
await food.save();
69-
response.status(201).send(food);
69+
response.status(201).json(food);
7070
});
7171

7272
// ...
@@ -83,8 +83,7 @@ Example:
8383

8484
app.put("/food/:id", async (request, response) => {
8585
await foodModel.findByIdAndUpdate(request.params.id, request.body);
86-
await foodModel.save();
87-
response.send(food);
86+
response.json(food);
8887
}
8988
});
9089

@@ -104,7 +103,7 @@ app.delete("/food/:id", async (request, response) => {
104103
const food = await foodModel.findByIdAndDelete(request.params.id);
105104

106105
if (!food) response.status(404).send("No item found");
107-
response.status(204).send();
106+
response.status(204).json();
108107
}
109108
});
110109

0 commit comments

Comments
 (0)