Skip to content

Instantly share code, notes, and snippets.

@piyushgarg-dev
Created April 22, 2020 09:32
Show Gist options
  • Save piyushgarg-dev/e1bf7d94f0c002339948620512d44562 to your computer and use it in GitHub Desktop.
Save piyushgarg-dev/e1bf7d94f0c002339948620512d44562 to your computer and use it in GitHub Desktop.
// Endpoint 1
app.get('/api', function(req, res){
res.send('Welcome to our API')
})
// Endpoint 2
app.get('/api/users', function(req, res){
res.json(userData);
})
// Endpoint 3
app.get('/api/user/:id', function(req, res){
const id = req.params.id;
const user = userData.find(user => user.id === id);
if (user) {
res.json(user)
}
else {
res.send('No User Found')
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment