-
Notifications
You must be signed in to change notification settings - Fork 529
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
Project Express API #528
base: master
Are you sure you want to change the base?
Project Express API #528
Conversation
…he server.js file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job Johanna! Just remember going forward to make use of query params instead of creating different endpoints to filter.
app.get("/elves/all", (request, response) => { | ||
|
||
// Return all elves | ||
response.json(elves); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hehe love the dataset! A more RESTful approach would be to name this endpoint just /elves
and then have different query params to use as filters, e.g.
/elves?top-twelves=true
/elves?title=backend dasher
app.get("/test", (request, response) => { | ||
response.send("Jingle bells, the server tells, it's up and running well!"); | ||
console.log("Jingle bells, the server tells, it's up and running well!"); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😆 ⭐
app.get("/elves/:id", (request, response) => { | ||
const id = request.params.id; | ||
|
||
const elf = elves.find((record) => record.elfID === +id); | ||
if (elf) { | ||
response.status(200).json(elf); | ||
} else { | ||
response.status(404).send("404 - No elf found with that ID"); | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⭐
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice error handling
View it live here