-
Notifications
You must be signed in to change notification settings - Fork 381
/
index.js
55 lines (36 loc) · 1.08 KB
/
index.js
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
// import the pets array from data.js
const pets = require('./data');
// init express app
const express = require('express');
const app = express();
const PORT = 8080;
// GET - / - returns homepage
app.get('/', (req, res) => {
// serve up the public folder as static index.html file
});
// hello world route
app.get('/api', (req, res) => {
res.send('Hello World!');
});
// get all pets from the database
app.get('/api/v1/pets', (req, res) => {
// send the pets array as a response
});
// get pet by owner with query string
app.get('/api/v1/pets/owner', (req, res) => {
// get the owner from the request
// find the pet in the pets array
const pet = pets.find(pet => pet.owner === owner);
// send the pet as a response
});
// get pet by name
app.get('/api/v1/pets/:name', (req, res) => {
// get the name from the request
// find the pet in the pets array
const pet = pets.find(pet => pet.name === name);
// send the pet as a response
});
app.listen(PORT, () => {
console.log('Server is listening on port ' + PORT);
});
module.exports = app;