Created
February 20, 2018 20:06
-
-
Save markwithers/d688e3efe26d2288bfe558dd73af2f72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express') | |
var app = express() | |
var port = process.env.PORT || 8080 | |
var router = express.Router() | |
router.get('/', function(req, res) { | |
res.json({ message: 'Welcome to the api!' }) | |
}) | |
router.get('/safe', function(req, res) { | |
res.json({ message: 'You got a success!' }) | |
}) | |
router.get('/risky', function(req, res) { | |
if (Math.random() > 0.5) { | |
res.json({ message: 'You got a success!' }) | |
} | |
else { | |
res.status(418).send('This is a teapot') | |
} | |
}) | |
app.use('/api', router) | |
app.listen(port) | |
console.log('listening on port ' + port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment