Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved the missing code #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const PORT = 8080;
// GET - / - returns homepage
app.get('/', (req, res) => {
// serve up the public folder as static index.html file
res.sendFile( __dirname + "/public/index.html")

});

Expand All @@ -21,30 +22,36 @@ app.get('/api', (req, res) => {
// get all pets from the database
app.get('/api/v1/pets', (req, res) => {
// send the pets array as a response
res.send(pets);

});

// get pet by owner with query string
app.get('/api/v1/pets/owner', (req, res) => {
// get the owner from the request
const owner = req.query.owner;


// find the pet in the pets array
const pet = pets.find(pet => pet.owner === owner);


// send the pet as a response
res.send(pet);

});

// get pet by name
app.get('/api/v1/pets/:name', (req, res) => {
// get the name from the request
const name = req.params.name;


// find the pet in the pets array
const pet = pets.find(pet => pet.name === name);

// send the pet as a response
res.send(pet);

});

Expand Down
Loading