Skip to content

Commit 55cf186

Browse files
committed
Finished
1 parent 85ee72e commit 55cf186

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
1+
The JavaScript Full-Stack Bootcamp: LEVEL 18 REST API (Lesson 80)
22

33
We created a REST API using Node.js and Express. This API uses set of GET and POST endpoints to allow us to get data out, and sending data in. We also use a MongoDB database to store this data.
44

55
Our goal is to create a trip cost calculator app. Imagine going on a trip, and you have your app (which can be a progressive web app, or a mobile app for example) where you add any expense you make. Gasoline, hotels, food, tickets and so on. When the trip ends, you archive it and it becomes part of the history - which you can navigate and see how much you spent in the past trips.
66

77
We don't create the frontend of the application here, just the API.
8+
9+
-Finished 8/9/20 by E.Cope.

tripcost/server.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const mongo = require('mongodb').MongoClient;
33

44
const app = express();
55
const url = 'mongodb://localhost:27017';
6-
76
app.use(express.json());
87

98
let db, trips, expenses;
@@ -22,6 +21,7 @@ mongo.connect(url, {
2221
expenses = db.collection('expenses');
2322
}
2423
);
24+
2525
////////////////////////////////////
2626

2727
app.post('/trip', (req, res) => {
@@ -37,8 +37,8 @@ app.post('/trip', (req, res) => {
3737
});
3838
});
3939

40-
app.get('/trips', (req, res) => {
4140

41+
app.get('/trips', (req, res) => {
4242
trips.find().toArray( (err, items) => {
4343
if (err) {
4444
console.error(err);
@@ -49,8 +49,8 @@ app.get('/trips', (req, res) => {
4949
});
5050
});
5151

52-
app.post('/expense', (req, res) => {
5352

53+
app.post('/expense', (req, res) => {
5454
expenses.insertOne(
5555
{ trip: req.body.trip,
5656
date: req.body.date,
@@ -68,8 +68,8 @@ app.post('/expense', (req, res) => {
6868
});
6969
});
7070

71+
7172
app.get('/expenses', (req, res) => {
72-
7373
expenses.find({trip: req.body.trip}).toArray( (err, items) => {
7474
if (err) {
7575
console.error(err);
@@ -80,6 +80,5 @@ app.get('/expenses', (req, res) => {
8080
});
8181
});
8282

83-
///////////////////////////////////
8483

8584
app.listen(3000, () => console.log('Server ready'));

0 commit comments

Comments
 (0)